home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap03 / howto03 / delphi10 / drwsutl3.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-10-19  |  101.2 KB  |  2,673 lines

  1. unit Drwsutl3;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl, DRWSUtl1;
  8.  
  9. const
  10.   EOC_CHANGEDIR = 1;  { Error Operation Code for change directory failure }
  11.   EOC_SOURCECOPY = 2; { Error Operation Code for source copy failure      }
  12.   EOC_DESTCOPY = 3;   { Error Operation Code for destination copy failure }
  13.   EOC_DELETEFILE = 4; { Error Operation Code for file delete failure      }
  14.   EOC_DELETEDIR = 5;  { Error Operation Code for directory delete failure }
  15.   EOC_RENAMEFILE = 6; { Error Operation Code for renaming failure         }
  16.   EOC_MAKEDIR = 7;    { Error Operation Code for MkDir failure            }
  17.   EOC_SETATTR = 8;    { Error Operation Code for Set Attributes failure   }
  18.  
  19.   FAC_COPY = 1;       { File Action Code for recursive copying            }
  20.   FAC_MOVE = 2;       { File Action Code for recursive moving             }
  21.   FAC_DELETE = 3;     { File Action Code for recursive deletion           }
  22. type
  23.   { This is a descendant of TFileListbox }
  24.   { Which puts icons of files into the   }
  25.   { Objects array rather than the stand- }
  26.   { ard bitmaps.                         }
  27.   TIconFileListBox = class( TFileListBox )
  28.   public
  29.     { public methods and data }
  30.     procedure ReadFileNames; override;
  31.     function GetNextSelection( SourceDirectory : String;
  32.               var CurrentItem : Integer ) : String;
  33.     constructor Create(AOwner : TComponent); override; { override create    }
  34.     procedure TheDblClick( Sender : TObject );{ This holds override dblclick }
  35.   end;
  36.   TFileWorkBench = class( TComponent )
  37.   public
  38.     GlobalError        : Integer;  { This is used by FMXUCopyFile for er code }
  39.     GlobalErrorType    : Integer;  { This holds the Operation code            }
  40.     function ForceTrailingBackSlash( const TheFileName : String ) : String;
  41.     function StripNonRootTrailingBackSlash(
  42.               const TheFileName : String ) : String;
  43.     procedure GetFileAttributes( TheFile : String; var IsDirectory , IsArchive ,
  44.                 IsVolumeID , IsHidden , IsReadOnly , IsSysFile : Boolean );
  45.     procedure HandleIOException( TheOpCode : Integer; ThePath : String;
  46.                                  TheMessage : String; TheCode : Integer );
  47.     procedure HandleDOSError( TheOpCode : Integer; ThePath : String;
  48.                 TheCode : Integer );
  49.     function CopyFile( TargetPath ,
  50.                DestinationPath : String ) : Boolean;
  51.     procedure ChangeTheDirectory( NewPath : String );
  52.     procedure ChangeTheDriveAndDirectory( NewDrive : Integer );
  53.     procedure CopyTheFile( OldPath , NewPath : String );
  54.     procedure MoveTheFile( OldPath , NewPath : String );
  55.     procedure DeleteTheFile( ThePath : String );
  56.     procedure RenameTheFile( OldPath , NewName : String );
  57.     procedure CreateNewDirectory( NewPath : String );
  58.     procedure RemoveDirectory( ThePath : String );
  59.     procedure SetFileAttributes( TheFile  : String; TheAttributes : Integer );
  60.     procedure RecursivelyCopyDirectory( OldPath , NewPath : String );
  61.     procedure RecursivelyMoveDirectory( OldPath , NewPath : String );
  62.     procedure RecursivelyDeleteDirectory( ThePath : String );
  63.     procedure HandleRecursiveAction( StartingPath , NewPath : String;
  64.                ActionCode : Integer );
  65.   end;
  66.   TFileIconPanel = class( TPanel )
  67.   private
  68.     { Private declarations }
  69.     FHighlightColor : TColor;                 { This holds bright edge bevel }
  70.     FShadowColor    : TColor;                 { This holds dark edge bevel   }
  71.     procedure TheMouseDown(Sender: TObject;
  72.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  73.     procedure TheMouseUp(Sender: TObject;
  74.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  75.     procedure WMLButtonDblClk(var Message: TWMLButtonDblClk);
  76.      message WM_LBUTTONDBLCLK;
  77.     procedure TheDragOver(Sender, Source: TObject; X,
  78.       Y: Integer; State: TDragState; var Accept: Boolean);
  79.     procedure TheDragDrop(Sender, Source: TObject; X,
  80.       Y: Integer);
  81.   protected                                   { event method procedure.      }
  82.     { Protected declarations }
  83.     procedure Paint; override;                { This allows custom painting  }
  84.   public
  85.     { Public declarations }
  86.     FTheIcon : TIcon;                         { This is the display icon    }
  87.     FTheName : String;                        { This is the filename        }
  88.     FTheLabel : TLabel;                       { This is the display label   }
  89.     Selected : Boolean;                       { This holds selection status }
  90.     constructor Create(AOwner : TComponent); override; { override create    }
  91.     procedure Initialize( PanelX              ,             { Left          }
  92.                           PanelY              ,             { Top           }
  93.                           PanelWidth          ,             { Width         }
  94.                           PanelHeight         ,             { Height        }
  95.                           PanelBevelWidth     ,             { Bevel Width   }
  96.                           LabelFontSize         : Integer;  { Font size     }
  97.                           PanelColor          ,             { Main color    }
  98.                           PanelHighlightColor ,             { Bright color  }
  99.                           PanelShadowColor    ,             { Dark color    }
  100.                           LabelTextColor        : TColor;   { Text color    }
  101.                           TheFilename         ,             { Filename      }
  102.                           LabelFontName         : String;   { Font name     }
  103.                           LabelFontStyle        : TFontStyles;  { Font style}
  104.                           ExtraData             : Integer       );  { Drive }
  105.     destructor Destroy; override;             { override destroy to free    }
  106.   end;
  107.   TFileIconPanelScrollBox = class( TScrollBox )
  108.   public
  109.     { Public methods and data }
  110.     TheFWB              : TFileWorkBench; { Used for file manipulation         }
  111.     IconsNeedRefreshing : Boolean;                   { Flag to redo display    }
  112.     TheIconSize        : Integer;   { Holds Individual Icon size               }
  113.     TheIconSpacing     : Integer;   { Holds total icon footprint               }
  114.     MaxIconsInARow     : Integer;   { Set for screen size.                     }
  115.     TheStoredHandle    : HWnd;
  116.     TheParentForm      : TForm;
  117.     procedure Update;                                { Called to reset display }
  118.     constructor Create( AOwner : TComponent ); override;  { Override inherited }
  119.     procedure ClearTheFIPs;                          { Clears the FIPs safely  }
  120.     procedure AddDriveIcons( var XCounter , YCounter : Integer ); { Add drives }
  121.     procedure GetColorsForFileIcon( TheFile : String;
  122.                var BC , HC , SC , TC : TColor );
  123.     procedure GetIconsForEntireDirectory( TargetPath  : String );
  124.     function GetNextSelection( SourceDirectory : String;
  125.               var CurrentItem : Integer ) : String;
  126.     procedure DisplayRecursiveSearchResults(
  127.       TheStartingDirectory : String );
  128.   end;
  129.   TIOManager = class( TComponent )
  130.   public
  131.     Parent : TForm;
  132.     WhichButton : TMouseButton;
  133.     WhichState  : TShiftState;
  134.     function WasLeftPressed : Boolean;
  135.     function WasRightPressed : Boolean;
  136.     function WasMiddlePressed : Boolean;
  137.     function WasALTPressed : Boolean;
  138.     function WasSHIFTPressed : Boolean;
  139.     function WasCTRLPressed : Boolean;
  140.     procedure OnF1Pressed(Sender: TObject; var Key: Word;
  141.      Shift: TShiftState);
  142.     procedure OnF2Pressed(Sender: TObject; var Key: Word;
  143.      Shift: TShiftState);
  144.     procedure OnF3Pressed(Sender: TObject; var Key: Word;
  145.      Shift: TShiftState);
  146.     procedure OnF4Pressed(Sender: TObject; var Key: Word;
  147.      Shift: TShiftState);
  148.     procedure OnF5Pressed(Sender: TObject; var Key: Word;
  149.      Shift: TShiftState);
  150.     procedure OnF6Pressed(Sender: TObject; var Key: Word;
  151.      Shift: TShiftState);
  152.     procedure OnF7Pressed(Sender: TObject; var Key: Word;
  153.      Shift: TShiftState);
  154.     procedure OnF8Pressed(Sender: TObject; var Key: Word;
  155.      Shift: TShiftState);
  156.     procedure OnF9Pressed(Sender: TObject; var Key: Word;
  157.      Shift: TShiftState);
  158.     procedure OnF10Pressed(Sender: TObject; var Key: Word;
  159.      Shift: TShiftState);
  160.     procedure OnF11Pressed(Sender: TObject; var Key: Word;
  161.      Shift: TShiftState);
  162.     procedure OnF12Pressed(Sender: TObject; var Key: Word;
  163.      Shift: TShiftState);
  164.  end;
  165.   { This procedure gets an icon for a file using FindExecutable  }
  166.   { and ExtractIcon. (assumes file/dir is passed)                }
  167.   procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  168.   { This procedure spaces out the bitbtn components on a tpanel }
  169.   procedure SpacePanelButtons( WhichPanel : TPanel );
  170.     procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  171.                GlobalErrorCode : Integer );
  172.  
  173. var TheIOManager : TIOManager;
  174.  
  175. implementation
  176. {$R DRWSUTL3.RES}                 { Import custom resource file }
  177. uses UFMGR12;
  178.  
  179. { It has been edited to return viable error codes!             }
  180. procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  181.             GlobalErrorCode : Integer );
  182. var
  183.   CopyBuffer: Pointer; { buffer for copying }
  184.   BytesCopied: Longint;
  185.   TheAttr : Integer;
  186.   Source, Dest: Integer; { handles }
  187. const
  188.   ChunkSize: Longint = 8192; { copy in 8K chunks }
  189. begin
  190.   GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
  191.   Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
  192.   if Source < 0 then
  193.   begin  { error creating source file }
  194.     GlobalErrorType := EOC_SOURCECOPY;
  195.     GlobalErrorCode := -IOResult;
  196.     if GlobalErrorCode = 0 then GlobalErrorCode := -157;
  197.     FreeMem( CopyBuffer, ChunkSize );
  198.     exit;
  199.   end;
  200.   Dest := FileCreate(DestName); { create output file; overwrite existing }
  201.   if Dest < 0 then
  202.   begin  { error creating destination file }
  203.     FileClose( Source );
  204.     GlobalErrorType := EOC_DESTCOPY;
  205.     GlobalErrorCode := -IOResult;
  206.     if GlobalErrorCode = 0 then GlobalErrorCode := -159;
  207.     FreeMem( CopyBuffer , ChunkSize );
  208.     exit;
  209.   end;
  210.   {$I-}
  211.   repeat
  212.     BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk}
  213.     if BytesCopied > 0 then { if we read anything... }
  214.     FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
  215.   until BytesCopied < ChunkSize; { until we run out of chunks }
  216.   {$I+}
  217.   GlobalErrorCode := -IOResult;  { get any error code which happens during copying }
  218.   FileClose(Dest); { close the destination file }
  219.   FileClose(Source); { close the source file }
  220.   FreeMem(CopyBuffer, ChunkSize); { free the buffer }
  221. end;
  222.  
  223. { This procedure spaces out the bitbtn components on a tpanel }
  224. procedure SpacePanelButtons( WhichPanel : TPanel );
  225. var TheCalculatedSpacing     ,            { Holds primary spacing }
  226.     TheFullCalculatedSpacing   : Integer; { Holds full spacing    }
  227.     Counter_1                  : Integer; { Loop counter          }
  228.     TotalIBs                   : Integer; { Gets total buttons    }
  229. begin
  230.   { Set up spacing values }
  231.   TotalIBs := WhichPanel.ControlCount;
  232.   TheCalculatedSpacing := (( WhichPanel.Width - 6 - ( TotalIbs * 49 ))
  233.    div ( TotalIbs + 1 ));
  234.   TheFullCalculatedSpacing := TheCalculatedSpacing + 49;
  235.   { Loop through all imported buttons and set their Left values }
  236.   for Counter_1 := 1 to WhichPanel.ControlCount do
  237.   begin
  238.     if Counter_1 = 1 then
  239.     begin
  240.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  241.        TheCalculatedSpacing;
  242.     end
  243.     else
  244.     begin
  245.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  246.        (( Counter_1 - 1 ) * TheFullCalculatedSpacing ) + TheCalculatedSpacing;
  247.     end;
  248.   end;
  249. end;
  250.  
  251. { This procedure gets an icon for a file using FindExecutable  }
  252. { and ExtractIcon. (assumes file/dir is passed)                }
  253. procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  254. var TheExt           : String; { File extension holder }
  255.     TheOtherPChar  ,           { Windows ASCIIZ string }
  256.     TheResultPChar ,           { Windows ASCIIZ string }
  257.     ThePChar         : PChar;  { Windows ASCIIZ string }
  258. begin
  259.   { Check for directory and if so get directory icon from RES file }
  260.   if (( FileGetAttr( TheName ) and faDirectory ) = faDirectory ) then
  261.   begin
  262.     { Set up the PChar to communicate with Windows }
  263.     GetMem( TheOtherPChar , 255 );
  264.     { Convert Pascal-style string to ASCIIZ Pchar }
  265.     StrPCopy( TheOtherPChar , 'DIRECTORY' );
  266.     { Use API call to return icon handle of Icon Resource in FILECTRL.RES }
  267.     TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  268.     { Release memory from PChar }
  269.     FreeMem( TheOtherPChar , 255 );
  270.     { Leave }
  271.     exit;
  272.   end;
  273.   { Assume archive file; get its extension }
  274.   TheExt := Uppercase( ExtractFileExt( TheName ));
  275.   { If not an executable/image file then use FindExecutable to get icon }
  276.   if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  277.       ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  278.   begin
  279.     { Grab three chunks of memory }
  280.     GetMem( TheOtherPChar , 255 );
  281.     GetMem( TheResultPChar , 255 );
  282.     GetMem( ThePChar , 255 );
  283.     { Set up the name and its directory in Windows string formats }
  284.     StrPCopy( ThePChar, TheName );
  285.     StrPCopy( TheOtherPChar , ExtractFilePath( TheName ));
  286.     { Use FindExecutable API call to get path and name of owning file }
  287.     if FindExecutable( ThePChar , TheOtherPChar , TheResultPChar ) > 31 then
  288.     begin
  289.       { If get a result of 32 or more then try to get first icon of owner }
  290.       { Using ExtractIcon API call; 0 indicates first icon.               }
  291.       TheIcon.Handle := ExtractIcon( hInstance , TheResultPchar , 0 );
  292.       { If a handle is 0 then no icon in owner, get default icon from RES file }
  293.       if TheIcon.Handle = 0 then
  294.       begin
  295.         GetMem( TheOtherPChar , 255 );
  296.         StrPCopy( TheOtherPChar , 'NOICON' );
  297.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  298.         FreeMem( TheOtherPChar , 255 );
  299.         exit;
  300.       end;
  301.     end
  302.     else
  303.     { if no assigned executable, then get default icon from RES file }
  304.     begin
  305.       GetMem( TheOtherPChar , 255 );
  306.       StrPCopy( TheOtherPChar , 'NOICON' );
  307.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  308.       FreeMem( TheOtherPChar , 255 );
  309.       exit;
  310.     end;
  311.     FreeMem( TheOtherPChar , 255 );
  312.     FreeMem( TheResultPChar , 255 );
  313.     FreeMem( ThePChar , 255 );
  314.   end
  315.   else
  316.   { Assume Windows Executable file, so get icon from it with ExtractIcon API }
  317.   begin
  318.     GetMem( ThePChar , 255 );
  319.     StrPCopy( ThePChar , TheName );
  320.     { If no icons in file then get default icon (note use FFFF for -1) }
  321.     if ExtractIcon( hInstance , ThePchar , 65535 ) = 0 then
  322.     begin
  323.       Freemem( ThePChar , 255 );
  324.       GetMem( TheOtherPChar , 255 );
  325.       StrPCopy( TheOtherPChar , 'NOICON' );
  326.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  327.       FreeMem( TheOtherPChar , 255 );
  328.       exit;
  329.     end
  330.     else
  331.     begin
  332.       { Try to get first icon for file }
  333.       TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  334.       FreeMem( ThePChar , 255 );
  335.       { If handle is 0 invalid icon format so use default from RES file }
  336.       if TheIcon.Handle = 0 then
  337.       begin
  338.         GetMem( TheOtherPChar , 255 );
  339.         StrPCopy( TheOtherPChar , 'NOICON' );
  340.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  341.         FreeMem( TheOtherPChar , 255 );
  342.         exit;
  343.       end;
  344.     end;
  345.   end;
  346. end;
  347.  
  348. { This procedure handles pressing of F1 for CCFileManagerForm }
  349. procedure TIoManager.OnF1Pressed(Sender: TObject; var Key: Word;
  350.   Shift: TShiftState);
  351. begin
  352.   MessageDlg( 'Help not implemented!' , mtInformation,[mbok],0);
  353. end;
  354.  
  355. { This procedure handles pressing of F2 for CCFileManagerForm }
  356. procedure TIoManager.OnF2Pressed(Sender: TObject; var Key: Word;
  357.   Shift: TShiftState);
  358. begin
  359.   TCCFileMgrForm( Parent ).BitBtn1Click( Sender );
  360. end;
  361.  
  362. { This procedure handles pressing of F3 for CCFileManagerForm }
  363. procedure TIoManager.OnF3Pressed(Sender: TObject; var Key: Word;
  364.   Shift: TShiftState);
  365. begin
  366.   TCCFileMgrForm( Parent ).BitBtn2Click( Sender );
  367. end;
  368.  
  369. { This procedure handles pressing of F4 for CCFileManagerForm }
  370. procedure TIoManager.OnF4Pressed(Sender: TObject; var Key: Word;
  371.   Shift: TShiftState);
  372. begin
  373.   TCCFileMgrForm( Parent ).BitBtn3Click( Sender );
  374. end;
  375.  
  376. { This procedure handles pressing of F5 for CCFileManagerForm }
  377. procedure TIoManager.OnF5Pressed(Sender: TObject; var Key: Word;
  378.   Shift: TShiftState);
  379. begin
  380.   TCCFileMgrForm( Parent ).BitBtn4Click( Sender );
  381. end;
  382.  
  383. { This procedure handles pressing of F6 for CCFileManagerForm }
  384. procedure TIoManager.OnF6Pressed(Sender: TObject; var Key: Word;
  385.   Shift: TShiftState);
  386. begin
  387.   TCCFileMgrForm( Parent ).BitBtn5Click( Sender );
  388. end;
  389.  
  390. { This procedure handles pressing of F7 for CCFileManagerForm }
  391. procedure TIoManager.OnF7Pressed(Sender: TObject; var Key: Word;
  392.   Shift: TShiftState);
  393. begin
  394.   TCCFileMgrForm( Parent ).BitBtn9Click( Sender );
  395. end;
  396.  
  397. { This procedure handles pressing of F8 for CCFileManagerForm }
  398. procedure TIoManager.OnF8Pressed(Sender: TObject; var Key: Word;
  399.   Shift: TShiftState);
  400. begin
  401.   TCCFileMgrForm( Parent ).BitBtn6Click( Sender );
  402. end;
  403.  
  404. { This procedure handles pressing of F9 for CCFileManagerForm }
  405. procedure TIoManager.OnF9Pressed(Sender: TObject; var Key: Word;
  406.   Shift: TShiftState);
  407. begin
  408.   TCCFileMgrForm( Parent ).Update;
  409. end;
  410.  
  411. { This procedure handles pressing of F10 for CCFileManagerForm }
  412. procedure TIoManager.OnF10Pressed(Sender: TObject; var Key: Word;
  413.   Shift: TShiftState);
  414. begin
  415.   TCCFileMgrForm( Parent ).BitBtn7Click( Sender );
  416. end;
  417.  
  418. { This procedure handles pressing of F11 for CCFileManagerForm }
  419. procedure TIoManager.OnF11Pressed(Sender: TObject; var Key: Word;
  420.   Shift: TShiftState);
  421. begin
  422.   TCCFileMgrForm( Parent ).BitBtn8Click( Sender );
  423. end;
  424.  
  425. { This procedure handles pressing of F12 for CCFileManagerForm }
  426. procedure TIoManager.OnF12Pressed(Sender: TObject; var Key: Word;
  427.   Shift: TShiftState);
  428. begin
  429.   TCCFileMgrForm( Parent ).BitBtn10Click( Sender );
  430. end;
  431.  
  432. { Returns True if the Left Button was pressed in the last mouse operation }
  433. function TIOManager.WasLeftPressed : Boolean;
  434. begin
  435.   if ( mbLeft = WhichButton ) then WasLeftPressed := true else
  436.    WasLeftPressed := false;
  437. end;
  438.  
  439. { Returns true if the Right Button was pressed in the last mouse operation }
  440. function TIOManager.WasRightPressed : Boolean;
  441. begin
  442.   if mbRight = WhichButton then WasRightPressed := true else
  443.    WasRightPressed := false;
  444. end;
  445.  
  446. { Returns true if the Middle Button was pressed in the last mouse operation }
  447. function TIOManager.WasMiddlePressed : Boolean;
  448. begin
  449.   if mbMiddle = WhichButton then WasMiddlePressed := true else
  450.    WasMiddlePressed := false;
  451. end;
  452.  
  453. { Returns true if the ALT key was down during the last IO operation }
  454. function TIOManager.WasALTPressed : Boolean;
  455. begin
  456.   if ssAlt in WhichState then WasALTPressed := true else
  457.    WasALTPressed := false;
  458. end;
  459.  
  460. { Returns true if either SHIFT key was down during the last IO operation }
  461. function TIOManager.WasSHIFTPressed : Boolean;
  462. begin
  463.   if ssShift in WhichState then WasSHIFTPressed := true else
  464.    WasSHIFTPressed := false;
  465. end;
  466.  
  467. { Returns true if the Control Key was down during the last IO operation }
  468. function TIOManager.WasCTRLPressed : Boolean;
  469. begin
  470.   if ssCtrl in WhichState then WasCTRLPressed := true else
  471.    WasCTRLPressed := false;
  472. end;
  473.  
  474.  
  475. { This procedure does a fully error-trapped change directory }
  476. procedure TFileWorkBench.ChangeTheDirectory( NewPath : String );
  477. var CurrentDirectory : String;
  478. begin
  479.   if NewPath = '..' then
  480.   begin { Back up one level }
  481.     {$I+}
  482.     try
  483.       { Find the current directory }
  484.       GetDir( 0 , CurrentDirectory );
  485.       { Use EFP to move up one level }
  486.       CurrentDirectory := ExtractFilePath( CurrentDirectory );
  487.       { Strip trailing \ if not root }
  488.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  489.       { Try the change to the new drive }
  490.       ChDir( CurrentDirectory );
  491.     except
  492.       { if any exception occurs instantiate exception and show }
  493.       On E:EInOutError do
  494.       begin
  495.         { Call custom error display/lookup procedure }
  496.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  497.          E.Message , E.ErrorCode );
  498.       end;
  499.     end;
  500.   end
  501.   else
  502.   begin { Change to explicit path }
  503.     {$I+}
  504.     try
  505.       { Get target directory path }
  506.       CurrentDirectory := NewPath;
  507.       { Strip trailing \ if not root }
  508.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  509.       { Try the change to the new drive }
  510.       ChDir( CurrentDirectory );
  511.     except
  512.       { if any exception occurs instantiate exception and show }
  513.       On E:EInOutError do
  514.       begin
  515.         { Call custom error display/lookup procedure }
  516.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  517.          E.Message , E.ErrorCode );
  518.       end;
  519.     end;
  520.   end;
  521. end;
  522.  
  523. { This procedure does a fully error-trapped change directory }
  524. procedure TFileWorkBench.ChangeTheDriveAndDirectory( NewDrive : Integer );
  525. var CurrentDirectory : String;
  526. begin
  527.   {$I+}
  528.   try
  529.     { Find the working directory on new drive }
  530.     GetDir( NewDrive , CurrentDirectory );
  531.     { Try the change to the new drive }
  532.     ChDir( CurrentDirectory );
  533.   except
  534.     { if any exception occurs instantiate exception and show }
  535.     On E:EInOutError do
  536.     begin
  537.       { Call custom error display/lookup procedure }
  538.       HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  539.        E.Message , E.ErrorCode );
  540.     end;
  541.   end;
  542. end;
  543.  
  544. { This procedure copies a single file with error trapping }
  545. procedure TFileWorkBench.CopyTheFile( OldPath , NewPath : String );
  546. var AResult : Boolean; { Internal data flag }
  547. begin
  548.   { If Copyfile returns false an error occurred }
  549.   AResult := CopyFile( OldPath , NewPath +
  550.    ExtractFileName( OldPath ));
  551.   { Display meaningful error message }
  552.   if not AResult then HandleDOSError( GlobalErrorType , OldPath, GlobalError );
  553. end;
  554.  
  555. { This procedure moves a file by copying and delete it }
  556. procedure TFileWorkBench.MoveTheFile( OldPath , NewPath : String );
  557. var AResult : Boolean; { Internal data flag }
  558.     TheFile : File;    { Use to get errors  }
  559. begin
  560.   { If Copyfile returns false an error occurred }
  561.   AResult := CopyFile( OldPath , NewPath +
  562.     ExtractFileName( OldPath ));
  563.   { Display meaningful error message }
  564.   if not AResult then HandleDOSError( GlobalErrorType ,
  565.     OldPath , GlobalError );
  566.   { After valid copying, delete source file }
  567.   {$I+}
  568.   if AResult then try
  569.     { Use this trick to get valid exception handling }
  570.     AssignFile( TheFile , OldPath );
  571.     { Use erase because Deletefile doesn't give exceptions! }
  572.     Erase( TheFile );
  573.   except
  574.     { if any exception occurs instantiate exception and show }
  575.     On E:EInOutError do
  576.     begin
  577.       { Call custom error display/lookup procedure }
  578.       HandleIOException( EOC_DELETEFILE , OldPath ,
  579.        E.Message , E.ErrorCode );
  580.     end;
  581.   end;
  582. end;
  583.  
  584. { This procedure safely deletes a single file }
  585. procedure TFileWorkBench.DeleteTheFile( ThePath : String );
  586. var TheFile : File; { Internal file handle }
  587. begin
  588.   {$I+}
  589.   try
  590.     { Use this trick to get valid exception handling }
  591.     AssignFile( TheFile , ThePath );
  592.     { Use erase because Deletefile doesn't give exceptions! }
  593.     Erase( TheFile );
  594.   except
  595.     { if any exception occurs instantiate exception and show }
  596.     On E:EInOutError do
  597.     begin
  598.       { Call custom error display/lookup procedure }
  599.       HandleIOException( EOC_DELETEFILE , ThePath ,
  600.        E.Message , E.ErrorCode );
  601.     end;
  602.   end;
  603. end;
  604.  
  605. { This procedure renames a file with full error trapping }
  606. procedure TFileWorkBench.RenameTheFile( OldPath , NewName : String );
  607. var TheFile : File; { Internal file handle }
  608. begin
  609.   {$I+}
  610.   try
  611.     { Use this trick to get valid exception handling }
  612.     AssignFile( TheFile , OldPath );
  613.     { Use this because RenameFile doesn't give exceptions! }
  614.     Rename( TheFile , NewName );
  615.   except
  616.     { if any exception occurs instantiate exception and show }
  617.     On E:EInOutError do
  618.     begin
  619.       { Call custom error display/lookup procedure }
  620.       HandleIOException( EOC_RENAMEFILE , OldPath  ,
  621.        E.Message , E.ErrorCode );
  622.     end;
  623.   end;
  624. end;
  625.  
  626. { This procedure creates a new directory with full error trapping }
  627. procedure TFileWorkBench.CreateNewDirectory( NewPath : String );
  628. begin
  629.   {$I+}
  630.   try
  631.     Mkdir( NewPath );
  632.   except
  633.     { if any exception occurs instantiate exception and show }
  634.     On E:EInOutError do
  635.     begin
  636.       { Call custom error display/lookup procedure }
  637.       HandleIOException( EOC_MAKEDIR , NewPath  ,
  638.        E.Message , E.ErrorCode );
  639.     end;
  640.   end;
  641. end;
  642.  
  643. { This procedure remove a directory with full error trapping }
  644. procedure TFileWorkBench.RemoveDirectory( ThePath : String );
  645. begin
  646.   {$I+}
  647.   try
  648.     Rmdir( ThePath );
  649.   except
  650.     { if any exception occurs instantiate exception and show }
  651.     On E:EInOutError do
  652.     begin
  653.       { Call custom error display/lookup procedure }
  654.       HandleIOException( EOC_DELETEDIR , ThePath  ,
  655.        E.Message , E.ErrorCode );
  656.     end;
  657.   end;
  658. end;
  659.  
  660. { Use this to set the attributes of a file with error trapping }
  661. procedure TFileWorkBench.SetFileAttributes( TheFile  : String;
  662.            TheAttributes : Integer );
  663. var TheResult : Integer; { Holds error code if any }
  664. begin
  665.   { Attempt to set the attributes }
  666.   TheResult := FileSetAttr( TheFile , TheAttributes );
  667.   { if negative number error, so signal }
  668.   if TheResult < 0 then
  669.    HandleDOSError( EOC_SETATTR , TheFile , -TheResult );
  670. end;
  671.  
  672. { This procedure recursively copies a directory to a new path }
  673. procedure TFileWorkBench.RecursivelyCopyDirectory( OldPath , NewPath : String );
  674. var TheDir : String; { Holds source directory }
  675. begin
  676.   { Get the source directory to copy }
  677.   TheDir := ExtractFileName( OldPath );
  678.   { Force a backslash to the newpath variable }
  679.   NewPath := ForceTrailingBackSlash( NewPath );
  680.   { Add the source directory to the target path }
  681.   NewPath := NewPath + TheDir;
  682.   { Create a new directory with the new name }
  683.   CreateNewDirectory( NewPath );
  684.   { Force a backslash for compatibility }
  685.   NewPath := FOrcetrailingBackSlash( NewPath );
  686.   { Do the recursive call }
  687.   HandleRecursiveAction( OldPath , NewPath , FAC_COPY );
  688. end;
  689.  
  690. { This procedure recursively moves a directory tree }
  691. procedure TFileWorkBench.RecursivelyMoveDirectory( OldPath , NewPath : String );
  692. var TheDir    : String; { Holds source directory  }
  693.     SavedPath : String; { Holds saved dir to kill }
  694. begin
  695.   { Get the source directory to move }
  696.   TheDir := ExtractFileName( OldPath );
  697.   { Force a backslash to the newpath variable }
  698.   NewPath := ForceTrailingBackSlash( NewPath );
  699.   { Save the starting path just in case }
  700.   SavedPath := OldPath;
  701.   { Add the source directory to the target path }
  702.   NewPath := NewPath + TheDir;
  703.   { Create a new directory with the new name }
  704.   CreateNewDirectory( NewPath );
  705.   { Force a backslash for compatibility }
  706.   NewPath := FOrcetrailingBackSlash( NewPath );
  707.   { Do the recursive call }
  708.   HandleRecursiveAction( OldPath , NewPath , FAC_MOVE );
  709.   { Remove the source directory }
  710.   RemoveDirectory( SavedPath );
  711. end;
  712.  
  713. { This procedure handles recursively deleting an entire directory tree }
  714. procedure TFileWorkBench.RecursivelyDeleteDirectory( ThePath : String );
  715. begin
  716.   HandleRecursiveAction( ThePath , '' , FAC_DELETE );
  717. end;
  718.  
  719.  
  720. { This is the generic routine to copy, move, and delete whole directory trees }
  721. procedure TFileWorkBench.HandleRecursiveAction( StartingPath , NewPath : String;
  722.            ActionCode : Integer );
  723. { VITAL!!! These variables MUST be local for recursrion to work! }
  724. var
  725.     Finished        : Boolean;         { Loop flag              }
  726.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  727.     TheResult       : Integer;         { return variable        }
  728.     TargetPath ,
  729.     FileMask   ,
  730.     TheWorkingDirectory ,
  731.     TheStoredWorkingDirectory ,
  732.     ModifiedDirectory  : String;       { path for FF/FN         }
  733.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  734.     ButtonColor   ,                    { main panel color       }
  735.     ButtonHLColor ,                    { bright panel color     }
  736.     ButtonSColor  ,                    { dark panel color       }
  737.     Textcolor       : TColor;          { label text color       }
  738.     TheFile         : File;
  739.  
  740. begin
  741.   { Set up the initial variables }
  742.   Finished := false;
  743.   TheWorkingDirectory := StartingPath;
  744.   TheStoredWorkingDirectory := TheWorkingDirectory;
  745.   TheWorkingDirectory := TheWorkingDirectory + '\*.*';
  746.   TargetPath := ExtractFilePath( TheWorkingDirectory );
  747.   { Make the call to FindFirst set to get any file }
  748.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  749.   { loop through all files in the directory and delete them }
  750.   while not Finished do
  751.   begin
  752.     { Make call to FindNext, using only SearchRecord from FindFirst }
  753.     TheResult := FindNext( TheSR );
  754.     { A -1 result means no more files so exit }
  755.     if TheResult < 0 then finished := true else
  756.     begin
  757.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  758.        <> faDirectory ) then
  759.       begin { A File }
  760.         case ActionCode of
  761.           FAC_COPY :
  762.               begin
  763.                 CopyTheFile( TargetPath + TheSR.Name , NewPath );
  764.               end;
  765.           FAC_MOVE :
  766.               begin
  767.                 MoveTheFile( TargetPath + TheSR.Name , NewPath );
  768.               end;
  769.           FAC_DELETE :
  770.               begin { Delete }
  771.                 if MessageDlg( 'Delete file ' + TargetPath + TheSR.Name + '?',
  772.                    mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  773.                     DeleteTheFile( TargetPath + TheSR.Name );
  774.               end;
  775.         end;
  776.       end;
  777.     end;
  778.   end;
  779.   { Call FindClose for Windows NT/Windows 95 compatibility }
  780.   FindClose( TheSR );
  781.   { Set up the variables to do recursive calls on all directories}
  782.   Finished := false;
  783.   ModifiedDirectory := TheStoredWorkingdirectory + '\*.*';
  784.   { Make the call to FindFirst set to get any file, ignore result }
  785.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  786.   while not Finished do
  787.   begin
  788.     { Make call to FindNext, using only SearchRecord from FindFirst }
  789.     TheResult := FindNext( TheSR );
  790.     { A -1 result means no more files so exit }
  791.     if TheResult < 0 then
  792.       finished := true
  793.     else
  794.     begin
  795.       if TheSR.Name <> '..' then { Ignore backup in this case }
  796.       begin
  797.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  798.          = faDirectory ) then
  799.         begin
  800.           { Send in the new directory name }
  801.           ModifiedDirectory := TheStoredWorkingDirectory  + '\' +
  802.            TheSR.Name;
  803.           { Reproduce directory structure for recursion in copy/move }
  804.           NewPath := NewPath + TheSR.Name;
  805.           case ActionCode of
  806.             FAC_COPY , FAC_MOVE :
  807.                begin { Create ahead for move and copy }
  808.                  { Make the new directory for moving and copying }
  809.                  CreateNewDirectory( NewPath );
  810.                  { Force a backslash for compatibility }
  811.                  NewPath := ForceTrailingBackSlash( NewPath );
  812.                end;
  813.             FAC_DELETE :
  814.                begin  { No prior action needed for Delete }
  815.                end;
  816.           end;
  817.           { Do the recursive call }
  818.           HandleRecursiveAction( ModifiedDirectory , NewPath , ActionCode );
  819.           case ActionCode of
  820.             FAC_COPY :
  821.                begin { no action for copy }
  822.                end;
  823.             FAC_MOVE , FAC_DELETE :
  824.                begin  { Delete }
  825.                  { Get a confirmation }
  826.                  if MessageDlg( 'Remove Directory ' + TargetPath + TheSR.Name
  827.                   + '?', mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  828.                    RemoveDirectory( TargetPath + TheSR.Name );
  829.                end;
  830.           end;
  831.         end;
  832.       end;
  833.     end;
  834.   end;
  835. end;
  836.  
  837. { This is a generic copy routine taken from Delphi sample code }
  838. { This function calls the sample Copy code and handles errors }
  839. function TFileWorkBench.CopyFile( TargetPath ,
  840.           DestinationPath : String ) : Boolean;
  841. begin
  842.   { Set global error value to no error }
  843.   GlobalError := 0;
  844.   { Call the sample procedure to do the copy }
  845.   FMXUCopyFile( TargetPath, DestinationPath , GlobalErrorType , GlobalError );
  846.   { If no error return true else return false }
  847.   if GlobalError < 0 then CopyFile := false else
  848.    CopyFile := true;
  849. end;
  850.  
  851. { This procedure handles displaying a user-friendly Dialog box with a }
  852. { Message for Delphi IO exception errors.                             }
  853. procedure TFileWorkBench.HandleIOException( TheOpCode : Integer;
  854.            ThePath : String; TheMessage : String; TheCode : Integer );
  855. var ErrorMessageString : String;  { Holds internal data }
  856.     OperationString    : String;  { Holds internal data }
  857. begin
  858.   { clear to check for unrecognized code }
  859.   ErrorMessageString := '';
  860.   { Check against imported code }
  861.   case TheCode of
  862.     2    : ErrorMessageString := 'File not found';
  863.     3    : ErrorMessageString := 'Path not found';
  864.     4    : ErrorMessageString := 'Too many open files';
  865.     5    : ErrorMessageString := 'File access denied';
  866.     6    : ErrorMessageString := 'Invalid file handle';
  867.     12    : ErrorMessageString := 'Invalid file access code';
  868.     15    : ErrorMessageString := 'Invalid drive number';
  869.     16  : ErrorMessageString := 'Cannot remove current directory';
  870.     17    : ErrorMessageString := 'Cannot rename across drives';
  871.     100    : ErrorMessageString := 'Disk read error';
  872.     101    : ErrorMessageString := 'Disk write error';
  873.     102    : ErrorMessageString := 'File not assigned';
  874.     103    : ErrorMessageString := 'File not open';
  875.     104    : ErrorMessageString := 'File not open for input';
  876.     105    : ErrorMessageString := 'File not open for output';
  877.   end;
  878.   case TheOpCode of
  879.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  880.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  881.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  882.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  883.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  884.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  885.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  886.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  887.   end;
  888.   { If not recognized use message; not a DOS error; reset cursor for neatness }
  889.   if ErrorMessageString = '' then
  890.   begin
  891.     Screen.Cursor := crDefault;
  892.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  893.      TheMessage , mtError , [mbOK],0);
  894.   end
  895.   else
  896.   begin
  897.     { Recognized DOS exception, reset cursor for neatness }
  898.     Screen.Cursor := crDefault;
  899.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  900.      ErrorMessageString , mtError , [mbOK], 0 );
  901.   end;
  902. end;
  903.  
  904. { This procedure handles displaying a user-friendly Dialog box with a }
  905. { Message for DOS error codes.                                        }
  906. procedure TFileWorkBench.HandleDOSError( TheOpCode : Integer;
  907.            ThePath : String;  TheCode : Integer );
  908. var ErrorMessageString : String;  { internal message holder }
  909.     OperationString : String;     { internal message holder }
  910. begin
  911.   { clear the message holder to check for unrecognized code }
  912.   ErrorMessageString := '';
  913.   { Negate the code back to normal number and check to set string }
  914.   case -TheCode of
  915.     2    : ErrorMessageString := 'File not found';
  916.     3    : ErrorMessageString := 'Path not found';
  917.     4    : ErrorMessageString := 'Too many open files';
  918.     5    : ErrorMessageString := 'File access denied';
  919.     6    : ErrorMessageString := 'Invalid file handle';
  920.     12    : ErrorMessageString := 'Invalid file access code';
  921.     15    : ErrorMessageString := 'Invalid drive number';
  922.     16  : ErrorMessageString := 'Cannot remove current directory';
  923.     17    : ErrorMessageString := 'Cannot rename across drives';
  924.     100    : ErrorMessageString := 'Disk read error';
  925.     101    : ErrorMessageString := 'Disk write error';
  926.     102    : ErrorMessageString := 'File not assigned';
  927.     103    : ErrorMessageString := 'File not open';
  928.     104    : ErrorMessageString := 'File not open for input';
  929.     105    : ErrorMessageString := 'File not open for output';
  930.     157 : ErrormessageString := 'Could not open Source File';
  931.     159 : ErrormessageString := 'Could not open Target File';
  932.   end;
  933.   case TheOpCode of
  934.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  935.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  936.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  937.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  938.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  939.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  940.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  941.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  942.   end;
  943.   { If the string is empty an unrecognized code was sent in }
  944.   if ErrorMessageString = '' then
  945.   begin
  946.     { Sent up db based on source or target error; reset cursor for neatness }
  947.     Screen.Cursor := crDefault;
  948.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' Error Code: ' +
  949.      IntToStr( TheCode ) , mtError , [mbOK],0);
  950.   end
  951.   else  { Code is recognized, use message from case statement }
  952.   begin
  953.     { Format the output for source or target error }
  954.     Screen.Cursor := crDefault;
  955.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  956.      ErrorMessageString , mtError , [mbOK], 0 );
  957.   end;
  958. end;
  959.  
  960. { This procedure sets the imported booleans to the file's attributes }
  961. procedure TFileWorkBench.GetFileAttributes( TheFile : String; var IsDirectory ,
  962.            IsArchive , IsVolumeID , IsHidden , IsReadOnly ,
  963.             IsSysFile : Boolean );
  964. var TheResult : Integer; { Traps for error code on VolumeID }
  965. begin
  966.   { Clear the imported flags for default }
  967.   IsDirectory := false;
  968.   IsArchive := false;
  969.   IsVolumeID := false;
  970.   IsHidden := False;
  971.   IsReadOnly := false;
  972.   IsSysFile := false;
  973.   { Make the Dos call }
  974.   TheResult := FileGetAttr( TheFile );
  975.   if TheResult < 0 then
  976.   begin
  977.     { Volume ID returns -2 (?) }
  978.     IsVolumeID := true;
  979.     { It has no other properties }
  980.     exit;
  981.   end;
  982.   { Use AND test to set all other properties }
  983.   if (( TheResult and faDirectory ) = faDirectory ) then IsDirectory := true;
  984.   if (( TheResult and faArchive ) = faArchive ) then IsArchive := true;
  985.   if (( TheResult and faVolumeID ) = faVolumeID ) then IsVolumeID := true;
  986.   if (( TheResult and faReadOnly ) = faReadOnly ) then IsReadOnly := true;
  987.   if (( TheResult and faHidden ) = faHidden ) then IsHidden := true;
  988.   if (( TheResult and faSysFile ) = faSysFile ) then IsSysFile := true;
  989. end;
  990.  
  991. { This function makes sure a pathname has a trailing \ }
  992. function TFileWorkBench.ForceTrailingBackSlash(
  993.           const TheFileName : String ) : String;
  994. var TempString : String;  { Used to hold function result }
  995. begin
  996.   { If no trailing \ add one (root will already have one.) }
  997.   if TheFileName[ Length( TheFileName ) ] <> '\' then
  998.    TempString := TheFileName + '\' else TempString := TheFileName;
  999.   { Return modified or non-modified string }
  1000.   ForceTrailingBackslash := TempString;
  1001. end;
  1002.  
  1003. { This function makes sure a non-root dir has no trailing \ }
  1004. function TFileWorkBench.StripNonRootTrailingBackSlash(
  1005.           const TheFileName : String ) : String;
  1006. var TempString : String ; { Used to hold function result }
  1007. begin
  1008.   { Default is no change }
  1009.   TempString := TheFileName;
  1010.   { If not root then }
  1011.   if Length( TheFileName ) > 3 then
  1012.   begin
  1013.     { If has a trailing backslash remove it }
  1014.     if TheFileName[ Length( TheFileName )] = '\' then
  1015.     begin
  1016.       TempString := Copy( TheFileName , 1 ,
  1017.        Length( TheFileName ) - 1 );
  1018.     end;
  1019.   end;
  1020.   { Export the final result }
  1021.   StripNonRootTrailingBackSlash := TempString;
  1022. end;
  1023.  
  1024. { This gets the next selected listbox item }
  1025. function TIconFileListBox.GetNextSelection( SourceDirectory : String;
  1026.           var CurrentItem : Integer ): String;
  1027. var TheResult : String;  { Internal storage }
  1028.     finished  : boolean; { Loop flag        }
  1029. begin
  1030.   { If out of items to check signal and exit }
  1031.   if CurrentItem > Items.Count then TheResult := '' else
  1032.   begin
  1033.     { Otherwise scan from current position till match or end }
  1034.     finished := false;
  1035.     while not finished do
  1036.     begin
  1037.       { Check against selected property }
  1038.       if Selected[ CurrentItem - 1 ] then
  1039.       begin
  1040.         { If selected then return it and abort loop }
  1041.         TheResult := SourceDirectory + Items[ CurrentItem - 1 ];
  1042.         finished := true;
  1043.         { Increment current position }
  1044.         CurrentItem := CurrentItem + 1;
  1045.      end
  1046.       else
  1047.       begin
  1048.         { Increment current position }
  1049.         CurrentItem := CurrentItem + 1;
  1050.         { Otherwise check for end of data and abort if out of entries }
  1051.         if CurrentItem > Items.Count then
  1052.         begin
  1053.           TheResult := '';
  1054.           finished := true;
  1055.         end;
  1056.       end;
  1057.     end;
  1058.   end;
  1059.   { Return stored result }
  1060.   GetNextSelection := TheResult;
  1061. end;
  1062.  
  1063. { Modified from VCL Source Copyright 1995 }
  1064. { Borland International, Inc.             }
  1065. { Use this to override display with icons }
  1066. procedure TIconFileListBox.ReadFileNames;
  1067. var
  1068.   AttrIndex   : TFileAttr;
  1069.   i           : Integer;
  1070.   FileExt     : string;
  1071.   MaskPtr     : PChar;
  1072.   Ptr         : PChar;
  1073.   AttrWord    : Word;
  1074.   TempPicture : TPicture;
  1075.   TempBmp     : TBitmap;
  1076.   TempIcon    : TIcon;
  1077. const
  1078.   Attributes: array[TFileAttr] of Word =
  1079.   ( DDL_READONLY , DDL_HIDDEN , DDL_SYSTEM , $0008 , DDL_DIRECTORY ,
  1080.     DDL_ARCHIVE  , DDL_EXCLUSIVE );
  1081. begin
  1082.   { if no handle allocated yet, this call will force         }
  1083.   { one to be allocated incorrectly (i.e. at the wrong time. }
  1084.   { In due time, one will be allocated appropriately.        }
  1085.   AttrWord := DDL_READWRITE;
  1086.   if HandleAllocated then
  1087.   begin
  1088.     { Set attribute flags based on values in FileType }
  1089.     for AttrIndex := ftReadOnly to ftArchive do
  1090.      if AttrIndex in FileType then
  1091.       AttrWord := AttrWord or Attributes[ AttrIndex ];
  1092.  
  1093.     { Use Exclusive bit to exclude normal files }
  1094.     if not ( ftNormal in FileType ) then
  1095.       AttrWord := AttrWord or DDL_EXCLUSIVE;
  1096.  
  1097.     ChDir( FDirectory ); { go to the directory we want }
  1098.     Clear;               { clear the list }
  1099.  
  1100.     MaskPtr := FMask;
  1101.     while MaskPtr <> nil do
  1102.     begin
  1103.       Ptr := StrScan ( MaskPtr , ';' );
  1104.       if Ptr <> nil then  Ptr^ := #0;
  1105.       { build the list }
  1106.       SendMessage( Handle , LB_DIR , AttrWord , Longint( MaskPtr ));
  1107.       if Ptr <> nil then
  1108.       begin
  1109.         Ptr^ := ';';
  1110.         Inc ( Ptr );
  1111.       end;
  1112.       MaskPtr := Ptr;
  1113.     end;
  1114.     { Now add the bitmaps }
  1115.     {---------------------------- begin custom code --------------------------}
  1116.     { Create the TPicture for exchange purposes }
  1117.     TempPicture := TPicture.Create;
  1118.     { Set it to icon widths }
  1119.     TempPicture.Bitmap.Width := 32;
  1120.     TempPicture.Bitmap.Height := 32;
  1121.     { Run down the list }
  1122.     for i := 0 to Items.Count - 1 do
  1123.     begin
  1124.       { Create a new temporary icon }
  1125.       TempIcon := TIcon.Create;
  1126.       { Call the custom DRWS routine to get icon for a file }
  1127.       GetIconForFile( Items[ i ] , TempIcon );
  1128.       { Put the icon on the bitmap for the picture via draw }
  1129.       { Note 1 , 1 due to bug in Draw?                      }
  1130.       TempPicture.Bitmap.Canvas.Draw( 1 , 1 , TempIcon );
  1131.       { Create a temporary bitmap }
  1132.       TempBmp := TBitmap.Create;
  1133.       { Set its width to those of the previous object's bitmaps }
  1134.       TempBmp.Width := 16;
  1135.       TempBmp.Height := 15;
  1136.       { Resize the icon's bitmap to the smaller size with stretchdraw }
  1137.       TempBmp.Canvas.StretchDraw( Rect( 1 , 1 , 15 , 14 ) ,
  1138.        TempPicture.Bitmap );
  1139.       { Set the Objects list to the bitmap }
  1140.       Items.Objects[ i ] := TempBmp;
  1141.       { Free the icon each iteration; don't free the TempBmp as list does }
  1142.       TempIcon.Free;
  1143.     end;
  1144.     { Free the TPicture exchange element }
  1145.     TempPicture.Free;
  1146.     {------------------------ end custom code --------------------------------}
  1147.     Change;
  1148.   end;
  1149. end;
  1150.  
  1151. { Use this to respond to dbl-clicking FLB filename }
  1152. procedure TIconFileListBox.TheDblClick(Sender: TObject);
  1153. begin
  1154.   { Call shellexec as a wrapper around ShellExecute API call }
  1155.   { False indicates failure, signal error                    }
  1156.   if not ShellExec( ExpandFileName( Items[ ItemIndex ] ), '' , '', false ,
  1157.    SW_SHOWNORMAL , false ) then MessageDlg('Could not Shell out to ' +
  1158.     Items[ ItemIndex ] , mtError, [mbOK], 0);
  1159. end;
  1160.  
  1161. { Create method for FIP                                }
  1162. constructor TIconFileListBox.Create( AOwner : TComponent );
  1163. begin
  1164.   { call inherited -- VITAL! }
  1165.   inherited Create( AOwner );
  1166.   { set the mouse method }
  1167.   OnDblClick := TheDblClick;
  1168. end;
  1169.  
  1170. { Create method for FIP                                }
  1171. constructor TFileIconPanel.Create( AOwner : TComponent );
  1172. begin
  1173.   { call inherited -- VITAL! }
  1174.   inherited Create( AOwner );
  1175.   { create icon and label components, making self owner/displayer }
  1176.   FTheIcon := TIcon.Create;
  1177.   FTheLabel := TLabel.Create( Self );
  1178.   FThelabel.Parent := Self;
  1179.   { Set own and labels mouse methods to stored methods }
  1180.   OnMouseUp := TheMouseUp;
  1181.   OnMouseDown := TheMouseDown;
  1182.   OnDragOver := TheDragOver;
  1183.   OnDragDrop := TheDragDrop;
  1184.   { Set alignment and autosize properties of the label }
  1185.   FTheLabel.Autosize := false;
  1186.   FTheLabel.Alignment := taCenter;
  1187.   { Set selected to false }
  1188.   Selected := false;
  1189. end;
  1190.  
  1191. procedure TFileIconPanel.WMLButtonDblClk(var Message: TWMLButtonDblClk);
  1192. var CurrentDirectory : String;    { Use to store dirs }
  1193.     TheDrive         : String;    { Get drive letter  }
  1194.     WhichDrive       : Integer;   { Get drive number  }
  1195.     ErrorCheck       : Integer;
  1196.     TheFWB           : TFileWorkBench;
  1197. begin
  1198.   { Create FileWorkBench for later use }
  1199.   TheFWB := TFileWorkBench.Create( Self );
  1200.   { Check for label or FIP sender }
  1201.   if FTheLabel.Caption = '..' then
  1202.   begin { deal with backup request }
  1203.     { Change to new directory }
  1204.     TheFWB.ChangeTheDirectory( '..' );
  1205.     { Call special method due to SendMessage problem! }
  1206.     TFileIconPanelScrollBox( Parent ).Update;
  1207.   end
  1208.   else
  1209.   begin
  1210.     { Check for DRIVE id in name }
  1211.     if Pos( 'DRIVE' , FTheName ) <> 0 then
  1212.     begin { Double Click on a Drive Icon }
  1213.       { Pull out the letter from name }
  1214.       TheDrive := Copy( FtheName , 7 , 1 );
  1215.       { Convert it to a number }
  1216.       WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  1217.       TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  1218.       { Call special method due to SendMessage problem! }
  1219.       TFileIconPanelScrollBox( Parent ).Update;
  1220.     end
  1221.     else
  1222.     begin { Double click on a dir/file icon }
  1223.       if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1224.       begin { A directory, change to it }
  1225.         { Since full path in name, simply change to it! }
  1226.         TheFWB.ChangeTheDirectory( FTheName );
  1227.         { Call special method due to SendMessage problem! }
  1228.         TFileIconPanelScrollBox( Parent ).Update;
  1229.       end
  1230.       else
  1231.       begin { A file; attempt to shellexecute it }
  1232.         { Call shellexec as a wrapper around ShellExecute API call }
  1233.         { False indicates failure, signal error                    }
  1234.         if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL , false )
  1235.          then MessageDlg('Could not Shell out to ' + FTheName , mtError,
  1236.           [mbOK], 0);
  1237.       end;
  1238.     end;
  1239.   end;
  1240.   TheFWB.Free; { This prevents resource leak }
  1241. end;
  1242.  
  1243. { Initialization method for FIP                                         }
  1244. procedure TFileIconPanel.Initialize( PanelX              ,
  1245.                                      PanelY              ,
  1246.                                      PanelWidth          ,
  1247.                                      PanelHeight         ,
  1248.                                      PanelBevelWidth     ,
  1249.                                      LabelFontSize         : Integer;
  1250.                                      PanelColor          ,
  1251.                                      PanelHighlightColor ,
  1252.                                      PanelShadowColor    ,
  1253.                                      LabelTextColor        : TColor;
  1254.                                      TheFilename         ,
  1255.                                      LabelFontName         : String;
  1256.                                      LabelFontStyle        : TFontStyles;
  1257.                                      ExtraData             : Integer );
  1258.  
  1259. var TheLabelHeight ,             { Holder for label pixel height }
  1260.     TheLabelWidth    : Integer;  { Holder for label pixel width  }
  1261.     TheOtherPChar    : PChar;    { Windows ASCIIZ string         }
  1262. begin
  1263.   { Set the basic properties based on imported parameters }
  1264.   Left := PanelX;
  1265.   Top := PanelY;
  1266.   Width := PanelWidth;
  1267.   Height := PanelHeight;
  1268.   Color := PanelColor;
  1269.   BevelWidth := PanelBevelWidth;
  1270.   FHighlightColor := PanelHighlightColor;
  1271.   FShadowColor := PanelShadowColor;
  1272.   FTheName := TheFilename;
  1273.   { If the ExtraData field is non-0 then a drive is being sent in }
  1274.   if ExtraData <> 0 then
  1275.   begin
  1276.     { Use the data field value to determine which icon to get from RES file }
  1277.     case ExtraData of
  1278.       1 : begin
  1279.             GetMem( TheOtherPChar , 255 );
  1280.             StrPCopy( TheOtherPChar , 'FLOPPY35' );
  1281.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1282.             FreeMem( TheOtherPChar , 255 );
  1283.           end;
  1284.       2 : begin
  1285.             GetMem( TheOtherPChar , 255 );
  1286.             StrPCopy( TheOtherPChar , 'FIXEDHD' );
  1287.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1288.             FreeMem( TheOtherPChar , 255 );
  1289.           end;
  1290.       3 : begin
  1291.             GetMem( TheOtherPChar , 255 );
  1292.             StrPCopy( TheOtherPChar , 'NETWORKHD' );
  1293.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1294.             FreeMem( TheOtherPChar , 255 );
  1295.           end;
  1296.       4 : begin
  1297.             GetMem( TheOtherPChar , 255 );
  1298.             StrPCopy( TheOtherPChar , 'CDROM' );
  1299.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1300.             FreeMem( TheOtherPChar , 255 );
  1301.           end;
  1302.       5 : begin
  1303.             GetMem( TheOtherPChar , 255 );
  1304.             StrPCopy( TheOtherPChar , 'RAM' );
  1305.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1306.             FreeMem( TheOtherPChar , 255 );
  1307.           end;
  1308.     end;
  1309.     { The FileNme property is already set up for the caption; use directly }
  1310.     FTheLabel.Caption := TheFilename;
  1311.     { Set up the hint for later use (make sure to set ShowHint) }
  1312.     Hint := 'Change to ' + TheFileName;
  1313.     ShowHint := true;
  1314.     { Set up all imported label properties and center it for drawing }
  1315.     with FTheLabel do
  1316.     begin
  1317.       Font.Name := LabelFontName;
  1318.       Font.Size := LabelFontSize;
  1319.       Font.Style := LabelFontStyle;
  1320.       Font.Color := LabelTextColor;
  1321.       Canvas.Brush.Color := PanelColor;
  1322.       Canvas.Font := Font;
  1323.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  1324.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  1325.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  1326.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  1327.       Top := Top + Round( Self.Height * 0.75 );
  1328.       Height := TheLabelHeight;
  1329.       Width := TheLabelWidth;
  1330.     end;
  1331.   end
  1332.   else
  1333.   begin
  1334.     { A file or directory has been sent in; use GetIconForFile to obtain an }
  1335.     { icon either from the file, its owner, or a RES file default.          }
  1336.     GetIconForFile( FTheName , FTheIcon );
  1337.     { Check for the Backup caption and set it specially }
  1338.     if ExtractfileName( FThename ) = '..' then
  1339.     begin
  1340.       FTheLabel.Caption := '..';
  1341.       Hint := 'Up One Level';
  1342.     end
  1343.     else
  1344.     begin
  1345.       { Otherwise just get the filename for the label caption }
  1346.       { And the full path for the hint (used later.)          }
  1347.       FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  1348.       Hint := FTheName;
  1349.     end;
  1350.     { Activate showhint so hints are seen }
  1351.     ShowHint := true;
  1352.     { Set label properties with imported values and center for display }
  1353.     with FTheLabel do
  1354.     begin
  1355.       Font.Name := LabelFontName;
  1356.       Font.Size := LabelFontSize;
  1357.       Font.Style := LabelFontStyle;
  1358.       Font.Color := LabelTextColor;
  1359.       Canvas.Brush.Color := PanelColor;
  1360.       Canvas.Font := Font;
  1361.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  1362.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  1363.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  1364.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  1365.       Top := Top + Round( Self.Height * 0.75 );
  1366.       Height := TheLabelHeight;
  1367.       Width := TheLabelWidth;
  1368.     end;
  1369.   end;
  1370. end;
  1371.  
  1372. { Destroy method for FIP }
  1373. destructor TFileIconPanel.Destroy;
  1374. begin
  1375.   { free component resources }
  1376.   FTheIcon.Free;
  1377.   FTheLabel.Free;
  1378.   { call inherited -- VITAL! }
  1379.   inherited Destroy;
  1380. end;
  1381.  
  1382. { Mousedown method for FIP; used to allow dragging }
  1383. procedure TFileIconPanel.TheMouseDown(Sender: TObject;
  1384.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  1385. begin
  1386.   { Begin a conditional drag operation (false allows timer) }
  1387.   TheIOManager.WhichButton := Button;
  1388.   TheIOManager.WhichState := Shift;
  1389.   BeginDrag( false );
  1390.   { Currently ignore drive clicks }
  1391.   if Pos( 'DRIVE' , FTheName ) > 0 then exit;
  1392.   { Flip status of bevels }
  1393.   if BevelOuter = bvRaised then BevelOuter := bvLowered else
  1394.    BevelOuter := bvRaised;
  1395.   { Flip selected variable }
  1396.   Selected := not Selected;
  1397.   { Set redisplay }
  1398. end;
  1399.  
  1400. { Mouseup Method for FIP; used to allow dragging }
  1401. procedure TFileIconPanel.TheMouseUp(Sender: TObject;
  1402.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  1403. begin
  1404.   { End a drag operation without dropping; if dragged OK }
  1405.   { already handled.                                     }
  1406.   EndDrag( false );
  1407.   { If the right button is clicked, perform magic! }
  1408.   if Button = mbRight then
  1409.    TCCFileMgrForm( TFileIconPanelScrollbox( Parent ).
  1410.     TheParentForm ).BitBtn6Click( Self );
  1411.   { Redisplay on general principles }
  1412.   Invalidate;
  1413. end;
  1414.  
  1415. { Use this to generically OK DnD from FIPs }
  1416. procedure TFileIconPanel.TheDragOver(Sender, Source: TObject; X,
  1417.   Y: Integer; State: TDragState; var Accept: Boolean);
  1418. begin
  1419.   { Only accept from FileIconPanel components }
  1420.   if Source is TFileIconPanel then Accept := true else Accept := false;
  1421. end;
  1422.  
  1423. { Use this to accept Drag and Drop from other FIPs }
  1424. procedure TFileIconPanel.TheDragDrop(Sender, Source: TObject; X,
  1425.   Y: Integer);
  1426. var CurrentName ,                 { Holds work name}
  1427.     TheOldString : String;        { Holds Dir      }
  1428.     TargetDir    : String;        { target of op   }
  1429.     TheResult       : Integer;    { Modal res hold }
  1430.     SourceDirectory,
  1431.     TargetDirectory,
  1432.     CurrentDirectory : String;    { Use to store dirs }
  1433.     TheDrive         : String;    { Get drive letter  }
  1434.     WhichDrive       : Integer;   { Get drive number  }
  1435.     ErrorCheck       : Integer;
  1436.     TheFWB           : TFileWorkBench;
  1437.     ThePosition : Integer;
  1438.     Finished : Boolean;
  1439.     TheFIPSB : TFileIconPanelScrollBox;
  1440. begin
  1441.   { If drop target is .. then ignore }
  1442.   if FTheLabel.Caption = '..' then exit;
  1443.   { Likewise ignore Dnd from drive icons }
  1444.   if Pos( 'DRIVE' , TFileIconPanel( Source ).FtheName ) > 0 then exit;
  1445.   { Obtain the parent of the source FIP; may not be self }
  1446.   TheFIPSB := TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent );
  1447.   { Obtain source directory either as Dir or filepath }
  1448.   if (( FileGetAttr( TFileIconPanel( Source ).FTheName )
  1449.    and faDirectory ) = faDirectory ) then
  1450.   begin  { Directory; take whole path }
  1451.     SourceDirectory := TFileIconPanel( Source ).FTheName;
  1452.   end
  1453.   else
  1454.   begin { File; get pathname }
  1455.     SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  1456.   end;
  1457.   Sourcedirectory := TheFIPSB.TheFWB.ForceTrailingBackSlash( SourceDirectory );
  1458.   if Pos( 'DRIVE' , FTheName ) > 0 then
  1459.   begin { Drop onto a drive icon; perform action to its default dir }
  1460.     { Pull out the letter from name }
  1461.     TheDrive := Copy( FtheName , 7 , 1 );
  1462.     { Convert it to a number }
  1463.     WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  1464.     { Determine the target directory and drive }
  1465.     GetDir( WhichDrive , TargetDirectory );
  1466.     TargetDirectory := TheFIPSB.TheFWB.ForceTrailingbackSlash( TargetDirectory );
  1467.     { Check for shift to operate on all selections }
  1468.     if TheIOManager.WasSHIFTPressed then
  1469.     begin { Operate on all selections }
  1470.       { Obtain the parent directory of the FIP dragged over }
  1471.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  1472.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  1473.       { If SourceDir subset of TargetDir then abort; recursive failure }
  1474.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  1475.       begin
  1476.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  1477.         exit;
  1478.       end;
  1479.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  1480.       begin { Copy to different drives }
  1481.         if TheIOManager.WasALTPressed then
  1482.         begin { ALT overrides and does move }
  1483.           { Set up to get all current selections }
  1484.           ThePosition := 1;
  1485.           finished := false;
  1486.           while not finished do
  1487.           begin
  1488.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1489.                    ThePosition );
  1490.             { If returns blank string then out of selections }
  1491.             if CurrentName = '' then finished := true else
  1492.             begin
  1493.               { If a directory signal error }
  1494.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1495.               begin
  1496.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  1497.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1498.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  1499.                    TargetDirectory );
  1500.               end
  1501.               else
  1502.               begin
  1503.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  1504.               end;
  1505.             end;
  1506.             { Reset to normal cursor }
  1507.             Screen.Cursor := crDefault;
  1508.           end;
  1509.         end
  1510.         else
  1511.         begin { Default is to do copy like file manager }
  1512.           { Set up to get all current selections }
  1513.           ThePosition := 1;
  1514.           finished := false;
  1515.           while not finished do
  1516.           begin
  1517.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1518.                    ThePosition );
  1519.             { If returns blank string then out of selections }
  1520.             if CurrentName = '' then finished := true else
  1521.             begin
  1522.               { If a directory signal error }
  1523.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1524.               begin
  1525.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  1526.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1527.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  1528.                    TargetDirectory );
  1529.               end
  1530.               else
  1531.               begin
  1532.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  1533.               end;
  1534.             end;
  1535.             { Reset to normal cursor }
  1536.             Screen.Cursor := crDefault;
  1537.           end;
  1538.         end;
  1539.       end
  1540.       else
  1541.       begin { Copy to same drive }
  1542.         if TheIOManager.WasCTRLPressed then
  1543.         begin { CTRL overrides and does copy }
  1544.           { Set up to get all current selections }
  1545.           ThePosition := 1;
  1546.           finished := false;
  1547.           while not finished do
  1548.           begin
  1549.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1550.                    ThePosition );
  1551.             { If returns blank string then out of selections }
  1552.             if CurrentName = '' then finished := true else
  1553.             begin
  1554.               { If a directory signal error }
  1555.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1556.               begin
  1557.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  1558.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1559.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  1560.                    TargetDirectory );
  1561.               end
  1562.               else
  1563.               begin
  1564.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  1565.               end;
  1566.             end;
  1567.             { Reset to normal cursor }
  1568.             Screen.Cursor := crDefault;
  1569.           end;
  1570.         end
  1571.         else
  1572.         begin { Default is to do move like file manager }
  1573.           { Set up to get all current selections }
  1574.           ThePosition := 1;
  1575.           finished := false;
  1576.           while not finished do
  1577.           begin
  1578.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1579.                    ThePosition );
  1580.             { If returns blank string then out of selections }
  1581.             if CurrentName = '' then finished := true else
  1582.             begin
  1583.               { If a directory signal error }
  1584.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1585.               begin
  1586.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  1587.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1588.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  1589.                    TargetDirectory );
  1590.               end
  1591.               else
  1592.               begin
  1593.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  1594.               end;
  1595.             end;
  1596.             { Reset to normal cursor }
  1597.             Screen.Cursor := crDefault;
  1598.           end;
  1599.         end;
  1600.       end;
  1601.     end
  1602.     else
  1603.     begin { Operate on only source }
  1604.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  1605.       begin { Copy to different drives }
  1606.         if TheIOManager.WasALTPressed then
  1607.         begin { ALT overrides and does move }
  1608.           with Source as TFileIconPanel do
  1609.           begin
  1610.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  1611.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1612.               TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  1613.           end;
  1614.         end
  1615.         else
  1616.         begin { Default is to do copy like file manager }
  1617.           with Source as TFileIconPanel do
  1618.           begin
  1619.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  1620.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1621.               TheFIPSB.TheFWB.CopyTheFile( FtheName , TargetDirectory );
  1622.           end;
  1623.         end;
  1624.       end
  1625.       else
  1626.       begin { Copy to same drive }
  1627.         if TheIOManager.WasCTRLPressed then
  1628.         begin { CTRL overrides and does copy }
  1629.           with Source as TFileIconPanel do
  1630.           begin
  1631.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  1632.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1633.               TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  1634.           end;
  1635.         end
  1636.         else
  1637.         begin { Default is to do move like file manager }
  1638.           with Source as TFileIconPanel do
  1639.           begin
  1640.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  1641.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1642.              TheFIPSB.TheFWB.MoveTheFile( FtheName , TargetDirectory );
  1643.           end;
  1644.         end;
  1645.       end;
  1646.     end;
  1647.   end
  1648.   else
  1649.   begin { Drop onto dir or file icon }
  1650.     if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1651.     begin { Drop onto a directory; use its path as target }
  1652.       TargetDirectory := FTheName;
  1653.     end
  1654.     else
  1655.     begin { Drop onto a file; use its parent as target }
  1656.       TargetDirectory := ExtractFilePath( FTheName );
  1657.     end;
  1658.     Targetdirectory := TheFIPSB.TheFWB.ForceTrailingbackslash( TargetDirectory );
  1659.     { Check for shift to operate on all selections }
  1660.     if TheIOManager.WasSHIFTPressed then
  1661.     begin { Operate on all selections }
  1662.       { Obtain the parent directory of the FIP dragged over }
  1663.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  1664.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  1665.       { If SourceDir subset of TargetDir then abort; recursive failure }
  1666.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  1667.       begin
  1668.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  1669.         exit;
  1670.       end;
  1671.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  1672.       begin { Copy to different drives }
  1673.         if TheIOManager.WasALTPressed then
  1674.         begin { ALT overrides and does move }
  1675.           { Set up to get all current selections }
  1676.           ThePosition := 1;
  1677.           finished := false;
  1678.           while not finished do
  1679.           begin
  1680.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1681.                    ThePosition );
  1682.             { If returns blank string then out of selections }
  1683.             if CurrentName = '' then finished := true else
  1684.             begin
  1685.               { If a directory signal error }
  1686.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1687.               begin
  1688.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  1689.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1690.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  1691.                    TargetDirectory );
  1692.               end
  1693.               else
  1694.               begin
  1695.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  1696.               end;
  1697.             end;
  1698.             { Reset to normal cursor }
  1699.             Screen.Cursor := crDefault;
  1700.           end;
  1701.         end
  1702.         else
  1703.         begin { Default is to do copy like file manager }
  1704.           { Set up to get all current selections }
  1705.           ThePosition := 1;
  1706.           finished := false;
  1707.           while not finished do
  1708.           begin
  1709.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1710.                    ThePosition );
  1711.             { If returns blank string then out of selections }
  1712.             if CurrentName = '' then finished := true else
  1713.             begin
  1714.               { If a directory signal error }
  1715.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1716.               begin
  1717.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  1718.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1719.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  1720.                    TargetDirectory );
  1721.               end
  1722.               else
  1723.               begin
  1724.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  1725.               end;
  1726.             end;
  1727.             { Reset to normal cursor }
  1728.             Screen.Cursor := crDefault;
  1729.           end;
  1730.         end;
  1731.       end
  1732.       else
  1733.       begin { Copy to same drive }
  1734.         if TheIOManager.WasCTRLPressed then
  1735.         begin { CTRL overrides and does copy }
  1736.           { Set up to get all current selections }
  1737.           ThePosition := 1;
  1738.           finished := false;
  1739.           while not finished do
  1740.           begin
  1741.             { Call generic file getting routine based on current view}
  1742.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1743.                    ThePosition );
  1744.             { If returns blank string then out of selections }
  1745.             if CurrentName = '' then finished := true else
  1746.             begin
  1747.               { If a directory signal error }
  1748.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1749.               begin
  1750.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  1751.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1752.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  1753.                    TargetDirectory );
  1754.               end
  1755.               else
  1756.               begin
  1757.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  1758.               end;
  1759.             end;
  1760.             { Reset to normal cursor }
  1761.             Screen.Cursor := crDefault;
  1762.           end;
  1763.         end
  1764.         else
  1765.         begin { Default is to do move like file manager }
  1766.           { Set up to get all current selections }
  1767.           ThePosition := 1;
  1768.           finished := false;
  1769.           while not finished do
  1770.           begin
  1771.             { Call generic file getting routine based on current view}
  1772.               CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1773.                    ThePosition );
  1774.             { If returns blank string then out of selections }
  1775.             if CurrentName = '' then finished := true else
  1776.             begin
  1777.               { If a directory signal error }
  1778.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1779.               begin
  1780.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  1781.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1782.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  1783.                    TargetDirectory );
  1784.               end
  1785.               else
  1786.               begin
  1787.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  1788.               end;
  1789.             end;
  1790.             { Reset to normal cursor }
  1791.             Screen.Cursor := crDefault;
  1792.           end;
  1793.         end;
  1794.       end;
  1795.     end
  1796.     else
  1797.     begin { Operate on only source }
  1798.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  1799.       begin { Copy to different drives }
  1800.         if TheIOManager.WasALTPressed then
  1801.         begin { ALT overrides and does move }
  1802.           with Source as TFileIconPanel do
  1803.           begin
  1804.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1805.             begin
  1806.               if MessageDlg( 'Move Directory ' + FTheName + ' to ' +
  1807.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1808.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  1809.                  TargetDirectory );
  1810.             end
  1811.             else
  1812.             begin
  1813.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  1814.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1815.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  1816.             end;
  1817.           end;
  1818.         end
  1819.         else
  1820.         begin { Default is to do copy like file manager }
  1821.           with Source as TFileIconPanel do
  1822.           begin
  1823.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1824.             begin
  1825.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  1826.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1827.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  1828.                  TargetDirectory );
  1829.             end
  1830.             else
  1831.             begin
  1832.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  1833.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1834.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  1835.             end;
  1836.           end;
  1837.         end;
  1838.       end
  1839.       else
  1840.       begin { Copy to same drive }
  1841.         if TheIOManager.WasCTRLPressed then
  1842.         begin { CTRL overrides and does copy }
  1843.           with Source as TFileIconPanel do
  1844.           begin
  1845.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1846.             begin
  1847.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  1848.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1849.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  1850.                  TargetDirectory );
  1851.             end
  1852.             else
  1853.             begin
  1854.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  1855.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1856.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  1857.             end;
  1858.           end;
  1859.         end
  1860.         else
  1861.         begin { Default is to do move like file manager }
  1862.           with Source as TFileIconPanel do
  1863.           begin
  1864.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1865.             begin
  1866.               if MessageDlg( 'Move Directory ' + FtheName + ' to ' +
  1867.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1868.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  1869.                  TargetDirectory );
  1870.             end
  1871.             else
  1872.             begin
  1873.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  1874.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1875.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  1876.             end;
  1877.           end;
  1878.         end;
  1879.       end;
  1880.     end;
  1881.   end;
  1882.   { Call special method due to SendMessage problem! }
  1883.   TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent ).Update;
  1884.   TFileIconPanelScrollBox( Parent ).Update;
  1885. end;
  1886.  
  1887. { Paint method for FIP; overrides normal paint }
  1888. procedure TFileIconPanel.Paint;
  1889. var
  1890.   TheOtherRect   : TRect;   { Holds clientrect   }
  1891.   TopColor     ,            { Holds bright color }
  1892.   BottomColor    : TColor;  { Holds dark color   }
  1893.  
  1894. { These methods are from Borland Intl., copyright 1995 }
  1895. procedure Frame3D(    Canvas       : TCanvas;
  1896.                   var TheRect      : TRect;
  1897.                       TopColor   ,
  1898.                       BottomColor  : TColor;
  1899.                       Width        : Integer );
  1900.  
  1901. procedure DoRect;
  1902. var
  1903.   TopRight, BottomLeft: TPoint;
  1904. begin
  1905.   with Canvas, TheRect do
  1906.   begin
  1907.     TopRight.X := Right;
  1908.     TopRight.Y := Top;
  1909.     BottomLeft.X := Left;
  1910.     BottomLeft.Y := Bottom;
  1911.     Pen.Color := TopColor;
  1912.     PolyLine([BottomLeft, TopLeft, TopRight]);
  1913.     Pen.Color := BottomColor;
  1914.     Dec(BottomLeft.X);
  1915.     PolyLine([TopRight, BottomRight, BottomLeft]);
  1916.   end;
  1917. end;
  1918.  
  1919. begin
  1920.   Canvas.Pen.Width := 1;
  1921.   Dec(TheRect.Bottom); Dec(TheRect.Right);
  1922.   while Width > 0 do
  1923.   begin
  1924.     Dec(Width);
  1925.     DoRect;
  1926.     InflateRect(TheRect, -1, -1);
  1927.   end;
  1928.   Inc(TheRect.Bottom); Inc(TheRect.Right);
  1929. end;
  1930.  
  1931. procedure AdjustColors(Bevel: TPanelBevel);
  1932. begin
  1933.   TopColor := FHighlightColor;
  1934.   if Bevel = bvLowered then TopColor := FShadowColor;
  1935.   BottomColor := FShadowColor;
  1936.   if Bevel = bvLowered then BottomColor := FHighlightColor;
  1937. end;
  1938.  
  1939. { Custom code begins here }
  1940. begin
  1941.   { Get the rectangle of the control with API/method call }
  1942.   TheOtherRect := GetClientRect;
  1943.   { draw basic rectangle with basic color }
  1944.   with Canvas do
  1945.   begin
  1946.     Brush.Color := Color;
  1947.     FillRect(TheOtherRect);
  1948.   end;
  1949.   { Set up for top "icon" frame  and draw it with frame3d }
  1950.   TheOtherRect.Right := Width;
  1951.   TheOtherRect.Bottom := Round( Height * 0.75 ) - 6 ;
  1952.   if BevelOuter <> bvNone then
  1953.   begin
  1954.     AdjustColors(BevelOuter);
  1955.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1956.   end;
  1957.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  1958.   if BevelInner <> bvNone then
  1959.   begin
  1960.     AdjustColors(BevelInner);
  1961.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1962.   end;
  1963.   { Do the same for the lower "label" frame }
  1964.   TheOtherRect.Top := Round( Height * 0.75 ) - 5;
  1965.   TheOtherRect.Left := 0;
  1966.   TheOtherRect.Bottom := Height;
  1967.   TheOtherRect.Right := Width;
  1968.   if BevelOuter <> bvNone then
  1969.   begin
  1970.     AdjustColors(BevelOuter);
  1971.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1972.   end;
  1973.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  1974.   if BevelInner <> bvNone then
  1975.   begin
  1976.     AdjustColors(BevelInner);
  1977.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1978.   end;
  1979.   { Then draw the icon using canvas draw method }
  1980.   Canvas.Draw( (( Width - 32 ) div 2 ) + 1 ,
  1981.   ((( Round( Height * 0.75 ) - 6 ) - 32 ) div 2 ) + 1 , FTheIcon );
  1982. end;
  1983.  
  1984. { This procedure clears a scrollbox of all FileIconPanels }
  1985. procedure TFileIconPanelScrollbox.ClearTheFIPs;
  1986. var Counter_1 : Integer;
  1987.     TheComponent : TComponent;
  1988. begin
  1989.   { Note that must use while loop since component count continually }
  1990.   { decreases as removes are made!                                  }
  1991.   while ComponentCount > 0 do
  1992.   begin
  1993.     { Save the component as a generic TComponent }
  1994.     TheComponent := Components[ 0 ];
  1995.     { Call removecomponent to pull it out of the owner list for sb }
  1996.     { This avoids GPF when freeing the sb.                         }
  1997.     RemoveComponent( Components[ 0 ]);
  1998.     if ControlCount > 0 then
  1999.      RemoveControl( Controls[ 0 ] );
  2000.     { Typecast the pointer and free it to release memory and res. }
  2001.     TheParentForm.InsertComponent( TheComponent );
  2002.   end;
  2003. end;
  2004.  
  2005. { This procedure scans for drives and obtains their type and creates file }
  2006. { icon panels to represent them.                                          }
  2007. procedure TFileIconPanelScrollBox.AddDriveIcons( var XCounter ,
  2008.            YCounter : Integer );
  2009. type
  2010.   { This if from filectrl unit; reproduce here for completeness }
  2011.   TDriveType = (dtUnknown, dtNoDrive, dtFloppy, dtFixed, dtNetwork, dtCDROM,
  2012.                 dtRAM);
  2013. var
  2014.   DriveNum        : Integer;         { Used to get next drive via DOS fn   }
  2015.   IconType        : Integer;         { Used to hold icon type (defacto dt) }
  2016.   DriveChar       : Char;            { Used to hold drive letter           }
  2017.   DriveType       : TDriveType;      { Used for set-valued drive type      }
  2018.   Finished        : Boolean;         { Loop flag                           }
  2019.   TheFIP          : TFileIconPanel;  { Generic FileIconPanel variable      }
  2020.   ButtonColor   ,                    { Main panel color                    }
  2021.   ButtonHLColor ,                    { Bright panel color                  }
  2022.   ButtonSColor  ,                    { Dark panel color                    }
  2023.   Textcolor       : TColor;          { Label text color                    }
  2024.  
  2025. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2026. { Check whether drive is a CD-ROM.  Returns True if MSCDEX is installed }
  2027. {  and the drive is using a CD driver                                   }
  2028.  
  2029. function IsCDROM(DriveNum: Integer): Boolean; assembler;
  2030. asm
  2031.   MOV   AX,1500h { look for MSCDEX }
  2032.   XOR   BX,BX
  2033.   INT   2fh
  2034.   OR    BX,BX
  2035.   JZ    @Finish
  2036.   MOV   AX,150Bh { check for using CD driver }
  2037.   MOV   CX,DriveNum
  2038.   INT   2fh
  2039.   OR    AX,AX
  2040.   @Finish:
  2041. end;
  2042.  
  2043. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2044. { Check whether drive is a RAM drive.                                   }
  2045. function IsRAMDrive(DriveNum: Integer): Boolean; assembler;
  2046. var
  2047.   TempResult: Boolean;
  2048. asm
  2049.   MOV   TempResult,False
  2050.   PUSH  DS
  2051.   MOV   BX,SS
  2052.   MOV   DS,BX
  2053.   SUB   SP,0200h
  2054.   MOV   BX,SP
  2055.   MOV   AX,DriveNum
  2056.   MOV   CX,1
  2057.   XOR   DX,DX
  2058.   INT   25h  { read boot sector }
  2059.   ADD   SP,2
  2060.   JC    @ItsNot
  2061.   MOV   BX,SP
  2062.   CMP   BYTE PTR SS:[BX+15h],0F8h  { reverify fixed disk }
  2063.   JNE   @ItsNot
  2064.   CMP   BYTE PTR SS:[BX+10h],1  { check for single FAT }
  2065.   JNE   @ItsNot
  2066.   MOV   TempResult,True
  2067.   @ItsNot:
  2068.   ADD   SP,0200h
  2069.   POP   DS
  2070.   MOV   AL, TempResult
  2071. end;
  2072.  
  2073. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2074. { Finds the type of a drive letter.                                     }
  2075. function FindDriveType(DriveNum: Integer): TDriveType;
  2076. begin
  2077.   Result := TDriveType(GetDriveType(DriveNum));
  2078.   if (Result = dtFixed) or (Result = dtNetwork) then
  2079.   begin
  2080.     if IsCDROM(DriveNum) then Result := dtCDROM
  2081.     else if (Result = dtFixed) then
  2082.     begin
  2083.         { do not check for RAMDrive under Windows NT }
  2084.       if ((GetWinFlags and $4000) = 0) and IsRAMDrive(DriveNum) then
  2085.         Result := dtRAM;
  2086.     end;
  2087.   end;
  2088. end;
  2089.  
  2090. begin
  2091.   { Set the button colors to an aquamarine color scheme for drives }
  2092.   ButtonColor := clTeal;
  2093.   ButtonHLColor := clAqua;
  2094.   ButtonSColor := clNavy;
  2095.   TextColor := clblack;
  2096.   { Set initial variables before looping for all drives }
  2097.   finished := false;
  2098.   DriveNum := 0;
  2099.   while not finished do
  2100.   begin
  2101.     { Start with no drive found }
  2102.     IconType := 0;
  2103.     { Call the Borland method to get the drive info }
  2104.     DriveType := FindDriveType(DriveNum);
  2105.     { Set its letter and make it uppercase }
  2106.     DriveChar := Chr(DriveNum + ord('a'));
  2107.     DriveChar := Upcase(DriveChar);
  2108.     { Assign an icon based on the drive type; if no drive exists type is nil }
  2109.     case DriveType of
  2110.       dtFloppy  : IconType := 1;
  2111.       dtFixed   : IconType := 2;
  2112.       dtNetwork : IconType := 3;
  2113.       dtCDROM   : IconType := 4;
  2114.       dtRAM     : IconType := 5;
  2115.     end;
  2116.     { Set to check next drive letter }
  2117.     DriveNum := DriveNum + 1;
  2118.     { But if no match then out of drives so set exit flag }
  2119.     if IconType = 0 then finished := true;
  2120.     { If drive was valid then set up the new FileIconPanel on the imported }
  2121.     { Scrollbox                                                            }
  2122.     if not finished then
  2123.     begin
  2124.       { Create the FileIconPanel and set its parent for memory mgmt and display}
  2125.       TheFIP := TFileIconPanel.Create( Self );
  2126.       TheFIP.Parent := Self;
  2127.       { Call its initialize method with imported position values and the   }
  2128.       { preset color scheme, a drive caption, and a minimum font. Note the }
  2129.       { setting of the ExtraData field to non-zero; this signals a drive   }
  2130.       { rather than a file being sent in.                                  }
  2131.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2132.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2133.         7 , ButtonColor, ButtonHLColor,
  2134.        ButtonSColor , TextColor , 'DRIVE ' + DriveChar + ':' , 'MS Serif' , [] ,
  2135.        IconType );
  2136.       { Increment the column counter; if it exceeds max move to new row      }
  2137.       { Note that these are 'var' parameters and will export final position. }
  2138.       XCounter := XCounter + 1;
  2139.       if XCounter > MaxIconsInARow then
  2140.       begin
  2141.         XCounter := 1;
  2142.         YCounter := YCounter + 1;
  2143.       end;
  2144.     end;
  2145.   end;
  2146. end;
  2147.  
  2148. { This procedure assigns colors to FIP's based on file attributes }
  2149. procedure TFileIconPanelScrollBox.GetColorsForFileIcon( TheFile : String;
  2150.            var BC , HC , SC , TC : TColor );
  2151. var AmADir      ,             { Booleans hold file attribs }
  2152.     AmAnArchive ,
  2153.     AmAVolumeId ,
  2154.     AmHidden    ,
  2155.     AmReadOnly  ,
  2156.     AmSystem      : Boolean;
  2157. begin
  2158.   { Make the call to internal fileworkbench to set attributes }
  2159.   TheFWB.GetFileAttributes( TheFile , AmADir , AmAnArchive , AmAVolumeId ,
  2160.    AmHidden , AmReadOnly , AmSystem );
  2161.   { Volume ID has no subtypes }
  2162.   if AmAVolumeID then
  2163.   begin
  2164.     BC := clOlive;
  2165.     HC := clYellow;
  2166.     SC := clBlack;
  2167.     TC := clWhite;
  2168.     exit;
  2169.   end;
  2170.   { Check all directory combinations }
  2171.   if AmADir then
  2172.   begin
  2173.     BC := clNavy;
  2174.     HC := clBlue;
  2175.     SC := clBlack;
  2176.     TC := clWhite;
  2177.     if AmHidden then
  2178.     begin
  2179.       if AmReadOnly then
  2180.       begin
  2181.         if AmSystem then
  2182.         begin { One HECK of a file! }
  2183.           BC := clBlack;
  2184.           HC := clSilver;
  2185.           SC := clGray;
  2186.           TC := clWhite;
  2187.         end
  2188.         else
  2189.         begin { Dir,RO,Hid }
  2190.           BC := clMaroon;
  2191.           HC := clFuchsia;
  2192.           SC := clGreen;
  2193.           TC := clWhite;
  2194.         end;
  2195.       end
  2196.       else
  2197.       begin { Dir,Hid }
  2198.         BC := clPurple;
  2199.         HC := clFuchsia;
  2200.         SC := clBlack;
  2201.         TC := clWhite;
  2202.       end;
  2203.     end
  2204.     else
  2205.     begin
  2206.       if AmReadOnly then
  2207.       begin
  2208.         if AmSystem then
  2209.         begin { Dir,RO,Sys }
  2210.           BC := clMaroon;
  2211.           HC := clLime;
  2212.           SC := clGreen;
  2213.           TC := clWhite;
  2214.         end
  2215.         else
  2216.         begin { Dir,RO }
  2217.           BC := clGreen;
  2218.           HC := clLime;
  2219.           SC := clBlack;
  2220.           TC := clWhite;
  2221.         end;
  2222.       end
  2223.       else
  2224.       begin
  2225.         if AmSystem then
  2226.         begin { Dir,Sys }
  2227.           BC := clMaroon;
  2228.           HC := clRed;
  2229.           SC := clBlack;
  2230.           TC := clWhite;
  2231.         end;
  2232.       end;
  2233.     end;
  2234.   end
  2235.   else { Archive Only; check all combinations }
  2236.   begin
  2237.     BC := clSilver;
  2238.     HC := clWhite;
  2239.     SC := clGray;
  2240.     TC := clBlack;
  2241.     if AmHidden then
  2242.     begin
  2243.       if AmReadOnly then
  2244.       begin
  2245.         if AmSystem then
  2246.         begin { Hid,RO,Sys }
  2247.           BC := clRed;
  2248.           HC := clLime;
  2249.           SC := clPurple;
  2250.           TC := clBlack;
  2251.         end
  2252.         else
  2253.         begin { RO,Hid }
  2254.           BC := clLime;
  2255.           HC := clFuchsia;
  2256.           SC := clMaroon;
  2257.           TC := clBlack;
  2258.         end;
  2259.       end
  2260.       else
  2261.       begin { Hid }
  2262.         BC := clFuchsia;
  2263.         HC := clWhite;
  2264.         SC := clPurple;
  2265.         TC := clBlack;
  2266.       end;
  2267.     end
  2268.     else
  2269.     begin
  2270.       if AmReadOnly then
  2271.       begin
  2272.         if AmSystem then
  2273.         begin { RO,Sys }
  2274.           BC := clRed;
  2275.           HC := clLime;
  2276.           SC := clMaroon;
  2277.           TC := clBlack;
  2278.         end
  2279.         else
  2280.         begin { RO }
  2281.           BC := clLime;
  2282.           HC := clWhite;
  2283.           SC := clGreen;
  2284.           TC := clBlack;
  2285.         end;
  2286.       end
  2287.       else
  2288.       begin
  2289.         if AmSystem then
  2290.         begin { System }
  2291.           BC := clRed;
  2292.           HC := clWhite;
  2293.           SC := clMaroon;
  2294.           TC := clBlack;
  2295.         end;
  2296.       end;
  2297.     end;
  2298.   end;
  2299. end;
  2300.  
  2301. { This procedure gets all icons for an given directory, including drives and }
  2302. { standard subdirectories. It does not get special combinations or h/ro/sys  }
  2303. procedure TFileIconPanelScrollbox.GetIconsForEntireDirectory(
  2304.             TargetPath  : String );
  2305. var Finished        : Boolean;         { Loop flag              }
  2306.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  2307.     TheResult       : Integer;         { return variable        }
  2308.     TempPath        : String;          { path for FF/FN         }
  2309.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  2310.     RowCounter    ,                    { position in row of FIP }
  2311.     ColumnCounter   : Integer;         { position in col of FIP }
  2312.     ButtonColor   ,                    { main panel color       }
  2313.     ButtonHLColor ,                    { bright panel color     }
  2314.     ButtonSColor  ,                    { dark panel color       }
  2315.     Textcolor       : TColor;          { label text color       }
  2316.     IsADir ,                           { Variable for file attr }
  2317.     IsAnArchive ,
  2318.     IsAVolumeID,
  2319.     IsAReadOnlyFile,
  2320.     IsAHiddenFile ,
  2321.     IsASystemFile     : Boolean;
  2322.     MaxTextLength     : Integer;       { Used to safely set size}
  2323. begin
  2324.   { hide during refresh }
  2325.   Visible := false;
  2326.   { Get the icon sizes }
  2327.   TheFIP := TFileIconPanel.Create( Self );
  2328.   TheFIP.Parent := Self;
  2329.   TheFIP.FTheLabel.Canvas.Font.Name := 'MS Serif';
  2330.   TheFIP.FTheLabel.Canvas.Font.Size := 7;
  2331.   MaxTextLength := TheFIP.FTheLabel.Canvas.TextWidth( 'COMMAND.COM' );
  2332.   TheFIP.Free;
  2333.   TheIconSize := MaxTextLength + 13;
  2334.   TheIconSpacing := TheIconSize + 5;
  2335.   { Set up maximum icons per row based on screen size }
  2336.   MaxIconsInARow := ( Screen.Width div TheIconSpacing );
  2337.   { Set up the position counters }
  2338.   RowCounter := 1;
  2339.   ColumnCounter := 1;
  2340.   { Get the drives for the current machine }
  2341.   AddDriveIcons( ColumnCounter , RowCounter  );
  2342.   { Set up the initial variables }
  2343.   Finished := false;
  2344.   TempPath := TargetPath + '*.*';
  2345.   { Make the call to FindFirst set to get any file; will return '.' }
  2346.   { so discard it.                                                  }
  2347.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  2348.   { loop through all files in the directory and look for directories }
  2349.   while not Finished do
  2350.   begin
  2351.     { Make call to FindNext, using only SearchRecord from FindFirst }
  2352.     TheResult := FindNext( TheSR );
  2353.     { A -1 result means no more files so exit }
  2354.     if TheResult < 0 then finished := true else
  2355.     begin
  2356.       { Otherwise check for a directory attribute }
  2357.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  2358.        faDirectory ) then
  2359.       begin
  2360.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2361.          ButtonHLColor , ButtonSColor , TextColor );
  2362.         { If found create a new FileIconPanel on the imported scrollbox }
  2363.         { Note sending 0 ExtraData parameter to indicate file not drive }
  2364.         TheFIP := TFileIconPanel.Create( Self );
  2365.         TheFIP.Parent := Self;
  2366.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  2367.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize ,
  2368.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  2369.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  2370.         { Increment column counter and move to new row if past limit }
  2371.         ColumnCounter := ColumnCounter + 1;
  2372.         if ColumnCounter > MaxIconsInARow then
  2373.         begin
  2374.           ColumnCounter := 1;
  2375.           RowCounter := RowCounter + 1;
  2376.         end;
  2377.       end;
  2378.     end;
  2379.   end;
  2380.   { Call FindClose for Windows NT/Windows 95 compatibility }
  2381.   FindClose( TheSR );
  2382.   { Set up new initialization variables }
  2383.   Finished := false;
  2384.   TempPath := TargetPath + '*.*';
  2385.   { Make needed call to FindFirst and discard '.' }
  2386.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  2387.   while not Finished do
  2388.   begin
  2389.     { Loop through file again, this time getting only archive files }
  2390.     TheResult := FindNext( TheSR );
  2391.     { Result of -1 indicates no more files }
  2392.     if TheResult < 0 then Finished := true else
  2393.     begin
  2394.       { If faArchive file then add new FileIconPanel }
  2395.       TheFWB.GetFileAttributes(( Targetpath + TheSR.Name ) , IsADir ,
  2396.        IsAnArchive , IsAVolumeId , IsAHiddenFile , IsAReadOnlyFile ,
  2397.         IsASystemFile );
  2398.       if (( IsAnArchive ) and ( not IsADir )) then
  2399.       begin
  2400.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2401.          ButtonHLColor , ButtonSColor , TextColor );
  2402.         { Initialize new FileIconPanel and call initialize, sending 0 ED }
  2403.         TheFIP := TFileIconPanel.Create( Self );
  2404.         TheFIP.Parent := Self;
  2405.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  2406.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize ,
  2407.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  2408.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  2409.         { Increment column counter and if needed row counter }
  2410.         ColumnCounter := ColumnCounter + 1;
  2411.         if ColumnCounter > MaxIconsInARow then
  2412.         begin
  2413.           ColumnCounter := 1;
  2414.           RowCounter := RowCounter + 1;
  2415.         end;
  2416.       end;
  2417.     end;
  2418.   end;
  2419.   { Call findclose for w95 and exit }
  2420.   FindClose( TheSR );
  2421.   { Reset to visible }
  2422.   Visible := true;
  2423. end;
  2424.  
  2425. { Update method for FIPscrollbox }
  2426. procedure TFileIconPanelScrollBox.Update;
  2427. begin
  2428.   IconsNeedRefreshing := true;
  2429.   { Force a repaint }
  2430.   InvalidateRect( TheStoredHandle , nil , true );
  2431. end;
  2432.  
  2433. { Create method for FIPScrollbox }
  2434. constructor TFileIconPanelScrollBox.Create( AOwner : TComponent );
  2435. begin
  2436.   inherited Create( AOwner );
  2437.   TheFWB := TFileWorkBench.Create( Self );
  2438. end;
  2439.  
  2440. { This function returns the next selected file's name }
  2441. function TFileIconPanelScrollBox.GetNextSelection( SourceDirectory : String;
  2442.                            var CurrentItem : Integer ) : String;
  2443. var TheResult    : String;      { Holds result of function }
  2444.     TheComponent : TComponent;  { Used for typecast        }
  2445.     finished     : boolean;     { Loop control variable    }
  2446.     TheComponentCount : Integer;
  2447. begin
  2448.   TheComponentCount := ComponentCount;
  2449.   { If past end of components exit with no result }
  2450.   if CurrentItem > TheComponentCount then TheResult := '' else
  2451.   begin
  2452.     { Set loop counter and run till find match or run out }
  2453.     finished := false;
  2454.     while not finished do
  2455.     begin
  2456.       { Pull component out of the list and check it }
  2457.       TheComponent := Components[ CurrentItem - 1 ];
  2458.       { Increment counter for later }
  2459.       CurrentItem := CurrentItem + 1;
  2460.       { Do the typecast with AS }
  2461.       if TheComponent is TFileIconPanel then
  2462.       with TheComponent as TFileIconPanel do
  2463.       begin
  2464.         { If its selected make sure OK }
  2465.         if Selected then
  2466.         begin
  2467.           { Don't accept backup for this level of operation }
  2468.           if FTheLabel.Caption <> '..' then
  2469.           begin
  2470.             { Otherwise return the name and abort the loop }
  2471.             TheResult := FTheName;
  2472.             finished := true;
  2473.           end;
  2474.         end
  2475.         else
  2476.         begin
  2477.           { Check to see if out of components }
  2478.           if CurrentItem > TheComponentCount then
  2479.           begin
  2480.             { If so signal error and abort }
  2481.             TheResult := '';
  2482.             finished := true;
  2483.           end;
  2484.         end;
  2485.       end;
  2486.     end;
  2487.   end;
  2488.   GetNextSelection := TheResult;
  2489. end;
  2490.  
  2491. { This procedure places a selection of files in the display based on wildcards }
  2492. procedure TFileIconPanelScrollBox.DisplayRecursiveSearchResults(
  2493.            TheStartingDirectory : String );
  2494. var XCounter ,
  2495.     YCounter   : Integer;
  2496.  
  2497. { This procedure does a recursive file search by first getting all matches (in-}
  2498. { cluding directories) and adding them to the list. Then it checks for ALL the }
  2499. { subdirectories and does the same trick on them til there are no more matches }
  2500. { and no more subdirectories, at which point it exits and recurses back up.    }
  2501. procedure RecursiveFileSearch( TheWorkingDirectory : String; var XCounter ,
  2502.                                YCounter : Integer );
  2503.  
  2504. { VITAL!!! These variables MUST be local for recursrion to work! }
  2505. var
  2506.     Finished        : Boolean;         { Loop flag              }
  2507.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  2508.     TheResult       : Integer;         { return variable        }
  2509.     TargetPath ,
  2510.     FileMask   ,
  2511.     TheStoredWorkingDirectory ,
  2512.     ModifiedDirectory  : String;       { path for FF/FN         }
  2513.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  2514.     ButtonColor   ,                    { main panel color       }
  2515.     ButtonHLColor ,                    { bright panel color     }
  2516.     ButtonSColor  ,                    { dark panel color       }
  2517.     Textcolor       : TColor;          { label text color       }
  2518.  
  2519. begin
  2520.   { Set up the initial variables }
  2521.   Finished := false;
  2522.   TheStoredWorkingDirectory := TheWorkingDirectory;
  2523.   Targetpath := ExtractFilePath( TheWorkingDirectory );
  2524.   FileMask := ExtractFileName( TheWorkingDirectory );
  2525.   { Make the call to FindFirst set to get any file }
  2526.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  2527.   if TheResult < 0 then finished := true;
  2528.   if (( TheSr.Name <> '.' ) and ( TheSr.Name <> '..' ) and ( TheResult >= 0 ))
  2529.   then begin
  2530.     if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  2531.      faDirectory ) then
  2532.     begin { A directory }
  2533.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2534.        ButtonHLColor , ButtonSColor , TextColor );
  2535.       { If found create a new FileIconPanel on the imported scrollbox }
  2536.       { Note sending 0 ExtraData parameter to indicate file not drive }
  2537.       TheFIP := TFileIconPanel.Create( Self );
  2538.       TheFIP.Parent := Self;
  2539.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2540.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2541.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  2542.          + TheSr.Name , 'MS Serif' , [] , 0 );
  2543.       { Increment column counter and move to new row if past limit }
  2544.       XCounter := XCounter + 1;
  2545.       if XCounter > MaxIconsInARow then
  2546.       begin
  2547.         XCounter := 1;
  2548.         YCounter := YCounter + 1;
  2549.       end;
  2550.     end
  2551.     else
  2552.     begin { A File }
  2553.       { Set up the default color scheme for files }
  2554.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2555.        ButtonHLColor , ButtonSColor , TextColor );
  2556.       { If found create a new FileIconPanel on the imported scrollbox }
  2557.       { Note sending 0 ExtraData parameter to indicate file not drive }
  2558.       TheFIP := TFileIconPanel.Create( Self );
  2559.       TheFIP.Parent := Self;
  2560.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2561.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize , 3 ,
  2562.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  2563.          + TheSr.Name , 'MS Serif' , [] , 0 );
  2564.       { Increment column counter and move to new row if past limit }
  2565.       XCounter := XCounter + 1;
  2566.       if XCounter > MaxIconsInARow then
  2567.       begin
  2568.         XCounter := 1;
  2569.         YCounter := YCounter + 1;
  2570.       end;
  2571.     end;
  2572.   end;
  2573.   { loop through all files in the directory and look for matches }
  2574.   while not Finished do
  2575.   begin
  2576.     { Make call to FindNext, using only SearchRecord from FindFirst }
  2577.     TheResult := FindNext( TheSR );
  2578.     { A -1 result means no more files so exit }
  2579.     if TheResult < 0 then finished := true else
  2580.     begin
  2581.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  2582.        faDirectory ) then
  2583.       begin { A directory }
  2584.         { Set up the blue color scheme for directories }
  2585.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2586.          ButtonHLColor , ButtonSColor , TextColor );
  2587.         { If found create a new FileIconPanel on the imported scrollbox }
  2588.         { Note sending 0 ExtraData parameter to indicate file not drive }
  2589.         TheFIP := TFileIconPanel.Create( Self );
  2590.         TheFIP.Parent := Self;
  2591.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2592.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2593.            7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  2594.             TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  2595.         { Increment column counter and move to new row if past limit }
  2596.         XCounter := XCounter + 1;
  2597.         if XCounter > MaxIconsInARow then
  2598.         begin
  2599.           XCounter := 1;
  2600.           YCounter := YCounter + 1;
  2601.         end;
  2602.       end
  2603.       else
  2604.       begin { A File }
  2605.         { Set up the default color scheme for files }
  2606.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2607.          ButtonHLColor , ButtonSColor , TextColor );
  2608.         { If found create a new FileIconPanel on the imported scrollbox }
  2609.         { Note sending 0 ExtraData parameter to indicate file not drive }
  2610.         TheFIP := TFileIconPanel.Create( Self );
  2611.         TheFIP.Parent := Self;
  2612.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2613.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2614.           7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  2615.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  2616.         { Increment column counter and move to new row if past limit }
  2617.         XCounter := XCounter + 1;
  2618.         if XCounter > MaxIconsInARow then
  2619.         begin
  2620.           XCounter := 1;
  2621.           YCounter := YCounter + 1;
  2622.         end;
  2623.       end;
  2624.     end;
  2625.   end;
  2626.   { Call FindClose for Windows NT/Windows 95 compatibility }
  2627.   FindClose( TheSR );
  2628.   { Set up the variables to do recursive calls on all directories}
  2629.   Finished := false;
  2630.   ModifiedDirectory := ExtractFilePath( TheWorkingdirectory ) + '*.*';
  2631.   { Make the call to FindFirst set to get any file, ignore result }
  2632.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  2633.   while not Finished do
  2634.   begin
  2635.     { Make call to FindNext, using only SearchRecord from FindFirst }
  2636.     TheResult := FindNext( TheSR );
  2637.     { A -1 result means no more files so exit }
  2638.     if TheResult < 0 then finished := true
  2639.     else
  2640.     begin
  2641.       if TheSR.Name <> '..' then { Ignore backup in this case }
  2642.       begin
  2643.         { Do second check due to bug in FindNext }
  2644.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  2645.         = faDirectory ) then
  2646.         begin
  2647.           { Set up modified directory to recurse into }
  2648.           ModifiedDirectory := ExtractFilePath( TheStoredWorkingDirectory ) +
  2649.            TheSR.Name + '\' + FileMask;
  2650.           { Perform the recursion }
  2651.           RecursiveFileSearch( ModifiedDirectory , XCounter , YCounter );
  2652.         end;
  2653.       end;
  2654.     end;
  2655.   end;
  2656. end;
  2657.  
  2658. begin
  2659.   { Keep the scrollbox from updating during refresh }
  2660.   Visible := false;
  2661.   { Make the clear call }
  2662.   ClearTheFIPs;
  2663.   XCounter := 1;
  2664.   YCounter := 1;
  2665.   { Get the drives for the current machine }
  2666.   AddDriveIcons( XCounter , YCounter );
  2667.   RecursiveFileSearch( TheStartingDirectory , XCounter , YCounter );
  2668.   { Make the scrollbox visible again }
  2669.   Visible := true;
  2670. end;
  2671.  
  2672. end.
  2673.